Fix incorrect if termination