build main and testing functions