CRM-12809

#1, #2, #3 and #4 of issue CRM-12809.