some bugfixes and some debugging code