Added pagination, refactoring