some refactoring and style changes.