Use lambda to simplify code