Did some refactoring.

Based on cand report I extracted some logic in to some methods and
wrapped some of the more complex logic with better tests.