added comments and tweaks, final version in the folder 'final'