Added conditional guard to ensure that groups are called properly. Added a single unit test.