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

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