Restructure; add support for second output filename argument