Refactor the code a little, and add some intermediary objects.