moar documentation, lots of comments and bugfixes