Fix some potential crasher bugs