Several small bugfixes