Refactor: fix code smells.

Reduce complexity as suggested by code climate.