Pseudo-code following discussion with MB