add ref counters so that we can garbage collect
Add lookups to get rid of duplicate consts.

Add generic variable lookup.
Cleanup + doco.
doco
doco
fix crash and add doco
catch up on reality