Bug fixes, mostly found by Monisha