pages controller refactoring