Fixed some crash bugs