Fixed bugs in termination