added heuristic algorithm to minimize repeat assignments