Replace confusing and wrong lambda with an explicitly defined function