Refactoring and adding some comments to the publish script.