Improved scope checking rules