Some refactoring and reformatting
Slight optimization.