Extracted main simulation loop into simulator. Note: currently untested.
fixed some compile errors related to initial refactor