refactored experiment.js to be more DRY