Final Version of the Code