Bug fixes and other fixes