First pass of refactoring; removed unecessarily nested functions and changed get page scroll to use jQuery API.