First batch of scope rewriting and tests done.