Cherry picked 1774efba106c759c3e741d1b4e90cfdc9a210e65 from crashey
Cleaned up fix for issue #4