some reformatting and refactoring