Refactor getimages loop and reduce service calls