Fix key writing step