add subfunction for subsample