refactor to enable pagination