final version of code