Fixed memory leaks. Added future support for spatial condition grouping.