Writing equivalent closures with simplified code