Added conditional to buildDictionary foreach loop

Fixes situations where morphType is null
Updated code style
Merge pull request #3887 from davidrushton/4.1

Added conditional to buildDictionary foreach loop