moved simulation logic to factory.js