Working version of do_out (modulo bugs)