refine sample.c code by inspection