revised code for pages index