heavy improvements and bugfixes