Gnumch, Move several functions to js file and proper handle of screen rotation.