many improvements/refactoring