added cfg, refactored main