support for recursive groups and code cleanup

contribution by Arjen