Cleaned up pagination. Might need more simplification