refactor out pagination and utility functions, need to fix multiple click problem