fix error reporting; debug; cleanup