Refactored repo switching related code