Fixed a bug with termination checking