Fixed broken groups and issue with document closing