Misc changes and bug fixes