A lot of miscellaneous bug fixes.