Issue 854

Commit d2f2642 fixes the indentation, while commit 8c7d21b implements the fix to issue 854.

I'm not sure if the latter is correct, but the former can be cherry picked from this PR.