refactoring: use function instead of lambda