bug in control flow