a few bugfixes and added comments