Prevent ArrayIndexOutOfBoundsException