Crm 13964 QA fixes

QA fixes for http://issues.civicrm.org/jira/browse/CRM-13964 #comment-56923, #comment-57306, #comment-57610 

this consists work done by Atif in PR : https://github.com/civicrm/civicrm-core/pull/2570 (closed as it got stale) and various improvements on it.