Fix some more runtime bugs and add more debug info to error messages.