bug fixes + more meaningful diagnostics