Refactors pagination class

Consolidates repeated code and raises error if current page index is
less than 1 or greater than the total page count.