Changing goals to map instead of multiset.
Match is now immutable.