final version of code.