Refactored out the loops in selectable title directive for better readability.