Add flattenContext
Fix unit test