Debugging; improve some error messages and note outstanding bugs in TODO.