Better diagnostics

Issue #363.