numerous bugfixes