Added comments and minor bugfixes