getting out of infinite loop