Several minor bugfixes