done some refactoring and clean up