Misc bugs fixed