replace timeout with loop