CRM-20193, moved set of code into if condition for better readability