Finalized simulation code. Needs to be cleaned up, but runs.