fix potential NPE / ArrayIndexOutOfBounds