Stripped down version of this step from my notes. pseudo-code only.