refactored pages controller