extract get_pages into a method