More formatting cleanup and some minor refactoring
remove conflicts in order to merge