Initial version of the main script, supports collect and deploy functions - NOT FULLY TESTED