modify code for error messages to debug problem