refactoring and adding tests tmp progress