add sensible error handling