writing step to file, some optimizations