Refine code for data analysis