converted to function. made DRY with lambda