do some refactoring and additions