Cleanup some logic to make it easier to follow.