Mainly updating some comments and a handful of small bugfixes.
Probably ready to merge.