Refactoring for sample management