better error handling (see #5)