The origin of metastatic heterogeneity in tumors