fix bad loop issue