[major] refactor location-based groups algorithm