Refactored JS to try and make it more clear. Added buttons to the bottos of the pages.