cleanup varialbe scope leaks and tests