Refactored code. Seems neater, more modular