add find gaps, write flags

add find gaps