some bug fixes and logging