finished basic statmachine.js