various improvements, refactoring