Added a bunch of comments
various bugfixes