fixing control flow