Add machine-id to substitutions and clean up substitution logic.