Several minor bug corrections