Please see the code for details.

Zimin