Handle last page properly when paginating