Adding the final version of code