Some basic reformatting and refactoring