finishing up some refactoring and fixes