Many changes and bugfixes