DRY up the code a little and add gotoPage API call