Added autoteamswitch function, cleanups.