changed to atomic file replacement