Request items until response is not empty, refactor some code