check for undefined refs
add fail function