Miscelaneous bug fixes