logic for pagination button clicks changed