Initial version of the code (working)