Variable is undefined immediately after iterating over an empty list. Fixes #878