rafactoring and add logic