Misc code fixes