Misc bug fixes