Major refactoring to remove folds and fix environment generation.

Still need to fix native values (Id and INTC constructors).