Fix NPE bug