Updated the publish algorithm to deal with deps

Also refactored some of the clause generation code into separate files.
Note the tests are being worked on but the structure here should be mostly it.