updated saving code