Refactored function in example