Add the 5 habits portion of the fix for TRQ-1978 (this is now JIRA TRQ-1980). The crash is fixed and there is now some additional refactoring and unit testing.