ported from asimov main repo