Minor tweaks on error reporting and scope matching