fix saving functionality