Three-phase flash and distillation