Modularized code for my simulation.