Final code updated version