straighten up the logic flow