user contributed security fixes thanks to Eric Sesterhenn