Fixed major bugs and able to output simulation.