Fix some crash bugs