reduce memory usage when used with flattened()

also preserve parameter code