refactoring and merging some changes