Refactor + QC tests