refactoring and new functionality