fix bugs, add basic simulation loop