refactoring and minor changes