Bug fixes

Misc bug fixes