Fixed BUG with array index out of bounds