fix some crash and fix the code which cannot be compiled