bug fix for infinite loop