fix CRM-12004
fix CRM-12005
sync with upstream master
Merge pull request #14 from dlobo/CRM-12005

Fix for CRM-12005 and CRM-12004