Fix bugs in Model::context and error emission