Refactoring: Better separation of concerns.
Formatting improved