fix non-termination bug