Implements back to top, refactors some JavaScript