Refactored to a function.