Fix for ruby 1.9
Split the resolve loop into smaller methods for easier testing