Reorganize codes, subgame added, validation added, needs to be tested