some refactoring not tested