Cleanup and factorization