Improved pagepermission query + changes based on code review