Refactor to build command and outfile name gracefully