A number of bugfixes