rewrite the func , take the long code apart