Fix crash bugs