Several bugfixes (adapt to upstream changes)