Guard against nil mode.

Fixes #421