Fix undefined index error, fixes #2224