Slightly clearer (to me :) version of the MAST algorithm