A few bugs found, this is before changing to print to stdout instead of an output file