fixed scoping things, wiht mixing up locals/globals