Tern updates... From environment to defs

And some other code clean up