Final version of code.