refactoring, general improvements