little code cleanup and pagination support (ugly!)