Refactoring. sample_management_activity almost working. Few bugs remain