Break out deletion handling to a separate function
Break out deletion handling to a separate function

Start refactoring the gigantic loop by breaking out independent tests
into their own functions. Begin with the check for deleting a ref.

Make the repository object global to let other functions access its
configuration.

saab-simc-admin/workflow-tools,saab-simc-admin/workflow-tools