Fixed file saving when invalid