two critical bug fixes and added logging