adjust detect while logic