most of the control flow now in place