Adds statement ref validation to fix #280.

#280