move flag logic to the main func