better error handling - fixes #5