Issue #22: Fix numerous issues with old branch deletion code in order to get branch deletion working again, and add tests to verify their success in future commits.