CRM-15376 - Porting fixes from https://github.com/civicrm/civicrm-core/p...

...ull/4233 to 4.5 branch.

----------------------------------------
* CRM-15376:
  https://issues.civicrm.org/jira/browse/CRM-15376