bugfixes, added debugging messages