Lots of minor fixes and cleanup.