refine sample code