Fixed NPE bug