minor changes and more refactoring