refine implementation code