bugfixes and several tweaks