refactoring and create an example