clean the repetitive build process and converted to one function