work on function and optional flag