Refactor and clean up.

Add early returns and reduce complexity of methods.