fixed 1.39 to be more generalized and use lambda