updated saving and validation logic