Revert "Refined fix to index out of range error"

This reverts commit 27f75a9a0232b83fa2fcd00ffae049efc62d24ed.
Revert "Safer fix for latest commit"

This reverts commit 6e763ab2745ef3470dd14fd46104df1736e0639f.
Revert "Fixed index out of range error."

This reverts commit 44786606d46ab32dde40b843857d46cc27dc8fc7.