copied logic from macroflection, factored a bit and bumped to 2.11.0-M8 compliance