some refactoring + testing