Simplify metadata patch and fix associated unit test