Move finish handling out of mud code, and clean up a bit.