Miscellaneous bug fixes