Refactor machine with createMachine