fixed a few variable referencing problems