Misc bug fixing