fixed hanging on large input size problem