same as commit 7cbb76e87b2d4864230e563294aa46520d3cdacf from ringsail repo.