forward port security fix from 0.9.1, fixes #177