General improvements and bugfixes