Add better team management for rest api. Some code refactoring.