Temp patch for #465, first hunk I found to fix the problem

For #465 
Rather than the whole commit. But I'll @bbatsov figure out the better fix when he can.