Updated to last version. Reduced the code in over 100 lines, made it
simpler, nicer to read.
Adapted the code for the new constructor, added some comments.