changed to working in append mode