Miscellaneous fixes
Merge pull request #3465 from monishdeb/CRM-14627

This PR is partial and will submit the other half changes in my next PR. For sake of stale I am merging the PR.