Refactor machine stuff