refactor and test the page controller