some refactor in code, update tests