Fix for array out of bounds