refactored pages task, still not satisfied with it