reafactor main files