patch from Matthew Scala