Some bug fixes when assigning template id of next closest cluster.
Some bug fixes when assigning template id of next closest cluster.

d-grossman/magichour,d-grossman/magichour,d-grossman/magichour,d-grossman/magichour,d-grossman/magichour