using lambda to simplify code

using lambda to simplify code