Misc cleanup and improvements

Several unrelated commits.