index out of bounds error fixed