fixed bug exiting loop too early