refactored to use function builder