manual rebase from clochix/visi2, replaces #517