some changes and refactoring