refine code without closure function