more debug-printing and error-checking