refactoring, extract to method, change output filename, fix bug that the sample size is not the actual considered samplesize