v 1.2: pseudo code added