Change the logic so that you dont have to use flag.