integrating fork from @aerhard