Various changes and bugfixes