some cleanups; removed redutant global variables; add support for multiple configs;