Added logic to filter page, refactor.