Reorganised reading and writing of config file