fix logic for page changing