Fix for #177

Probably not very idiomatic, I'm a Python programmer. Also, I'm not familiar enough with the code to propose a correct solution; this one works for me.