fixed error in run loop logic