Config saving fix

I have also refactored config handling to remove  unnecessary file operations.