bug fix: error message reported wrong variable due to indexing problem