add @swang's patch to master, fixes #52