reworked #580. Spotted and patched by @theyonibomber