Numerous bugfixes.