Basic refactoring and correcting alignment of code
More refactoring