Print better error messages plus some other cleanups.

BB-153