refactored the PagesApiController