The first thing that I noticed about your code is that you have a lot of nested functions going on.
Have you considered refactoring the code to reduce the nesting? Break the code into two stage. In stage one, gather all of the deals and the linked record ids for the locations. Then in stage two, just gather the information for the location. Finally, present all the assembled data to your users.