Added logic for the page logic.
Added the logic for pagination.