Fix NPE issues