implemented pagination. needs refactoring, but works fully.