cleans up pagination logic