Various improvements and bugfixes