more bugfixes than should even have been necessary
merge