Implemented Scope Checking

Nasty - needs refactoring.