Moved the logic that decides which environment to run in, and improved the process. Now supports NODE_ENV as well.