re-factor machines.js