first and last page handling for pagination