fixed a bunch of scope problems