rpearce: Switch to using lambda's for cleaning up