Work in progress: Misc bug fixes