Merged two commits

XCode screwed up, so I merged two commits:

Adding a env var export script
serious refactoring