factor output code into nml-out