Added better saving logic