fixed some scoping issues