Various bugfixes and adjustments