Several bugfixes.