bugfixing and logging improvement