some refactoring and a part of issue #108