refactor and add simulate.js