changed sub-sample routine