Several fixes to bugs discovered through the IR type checker