Major overhaull in script, support file-based configuration.