Add a check if ValueType on returnResult before testing null - fix #812