code refactoring and some changes