use func to instead duplicate code