Refactored further, added formatting