Add Groups model and code refactoring