Added logic and pseudocode to work with pagination.