Clean up, reformatting, some refactoring