added $groups and clean-ups