add extra error messages and debug output