Fix bugs in f18a10704898ab6a0faedee6e123afb4388384f0.

Nickolai report.