LUN-368 -- fix to handle orphan templates and templates assigned to shared sites (PBS)
LUN-368 -- small code refactor
LUN-368 -- refactoring after code review
Review and merge unique template used when duplicates are stored (LUN-368)