Fixed the non-terminating issue.