bugfixes and add comments