better error messages and logging