Fix issue #2 Not a SCALAR reference

check if it is actual a reference before dereferencing it