Added comments and did some bugfixes.