Replaced extract function with foreach (broken tests)