added some control to saving