Refactor nm filtering

This fixes bugs where a filtered N:M include would be further nested than 1st level.