fix possible stack overflow due to inf recursion