mostly working, but something is causing lots of duplicates in the output file.  Recursion also still needs to be implemented.