Fix possible ArrayIndexOutOfBoundsException