CRM-12407

This fixes problem mentioned in 
http://issues.civicrm.org/jira/browse/CRM-12407
http://issues.civicrm.org/jira/browse/CRM-12402