Fix non-termination issue