refine code not tested