Refactor upgrade controller for rerun and analytics support
Fix upgrade script