refactor pages code