refactoring and some changes