Fix null dereferencing