Numerous small bugfixes.