Solved the termination bug