fix some critical errors and add some more logging statements