Out of array bounds error fixed