Refactored for better code climate.