implementation of build function