Fixed safe_exit bug