Refactor group code and introduce BP group support