Add exception hanlde and upgrade algorithm (mainly battle)