refactored to use as function