Added pseudocode (from Eduard).