You can find FULL solution for such situation here: http://stackoverflow.com/a/33454284/630169