logging, bugfixes, even more clean code