refactoring and make code clear