Fixed paging and sorting

Fixed paging and sorting. Now works correctly. Paging now works correctly.