defined pagePosition and refactored