backported some incremental bugfixes