fixes a couple of mem scoping issues