Better error handling.

Now errors are checked in place, and strict type checking is
enforced.