refactor array flattening into diff engine