First complete version of the code