Improved sniff to return correct scope in error message