var declarations moved out of loop
association.through not always defined