several changes and refactoring