refactor out page splitting JavaScript code into separate module