Perform an extra check to see whether an item exists before trying to iterate through item list.

Fixes #1034