Added comments, some bugfixes