Merge pull request #612 from kurund/CRM-12463-fixes

more work on CRM-12463
worked on CRM-12357
Merge pull request #614 from kurund/CRM-12357

worked on CRM-12357
whitespace fixes
worked on CRM-12463, more fixes