Refactoring sampling and adding output file wip