refactor for pagination