totalRows and totalPages not being correctly calculated