better error reporting, cleanup