refactor pagination and clean up html