added some changes to saving mechanism