Final Version of Code