refine existing code