Improved team allocation script