Adding a bunch of comments, found some bugs, fixed the fatal one
(which prevented compilation).