Fix #174 - check for undefined/null in dynamic refs
Test for #174