-- CRM-12719 applied patch and improved it.
Merge pull request #894 from ravishnair/CRM-12719

-- CRM-12719 applied patch and improved it.