CRM-15376 - Porting fixes from https://github.com/civicrm/civicrm-core/pull/4233 to 4.5 branch.

----------------------------------------
* CRM-15376:
  https://issues.civicrm.org/jira/browse/CRM-15376