Added helper methods, and some code refactoring to facilitate current environment detection.