Various small bugfixes. Look at the diff.