Pagination now works. The code around it is messy and needs clean up.