some refactoring and little improvements