Revised and formatted code
Applied refactorings