Improved exception handling. Still not perfect, but getting there.