fixed last flag not set bug