CRM-13861

Full fix for the second point mentioned in issue description.