Code tidy and measuring time for sampling