bug fixes and logging added