Refactored, added pagination