Factorize code related to measurement