Miscellaneous bug fixes for edge cases.