Update of PR 1603

I added @CartBlanche changes and added a check on a null reference that always seemed to happen when I ran my tests on PSM.