Refactorings

Refactorings and formatting