flatten code