Slight changes to the code for better documentation and some actually irrelevant bugfixes.