refactored groupsWithTargets locking