bug fixes and logging