Updated the publish algorithm to deal with dependencies

Quite a few changes related to this. Will update this description in a few.