some refactoring and adding tox tests