Refactored and reindented.