FIX for issue 1013 - also includes fixes bugs  not logged but related and  discovered while fixing 1013
Additional related fix to issue 1020
Merge conflicts resolved
Merge pull request #1064 from akwok18/issue-1013

Includes fixes to related bugs that were found (not logged)
Closes #1013 ; Closes #1020