apply patch from @kdravolin