Refactoring and added example