Commented code

The code is now relativel commented, so it is clearer what each part
does.