refactor main and cfg