Import three following patches

Bugfixes and early improvements.