Several changes and bugfixes