pull out save into function