Bug fixes and various changes