Factor out common code for path transformations