Assorted bugfixes