some fixes
some refactoring