Refactor the code. Add simulation class.

Run algorithm codes are moved from main to simulation class.