Better error handling.
Minor cleanups.