capago_upgrader: Improve script to call searchAndActivate once and minor changes to make the code more readable