Use lambdas and some type inference. Other minor cleanups.