Functionning version of the code