final and submitted version. All the code is commented