Added an extra check to assign(Value*) in the handler to not make multiple shared pointers for the same pointer

This is essentially a bug fix for the new test where I assign the value
from a foreach loop to a variable so I can use it outside the loop later
on. Which would cause a crash before due to creation of multiple shared
pointers.