Added more debug statements and error messages.