Wrote a scope checking function