fixed non termination issue