Crm 13964

This PR consists of implementation of issue http://issues.civicrm.org/jira/browse/CRM-13964.

Also this PR consists of 50% implementation of http://issues.civicrm.org/jira/browse/CRM-13965 issue.

note this is without test cases, will be submitting a PR soon for it.