Final code

Finished and published version.