pseudo-merge from pyrf/master