implements save to function