ok, it was mis-behaving because the function Merlin() was returning an object, and objects can't be used in an expression by itself, so i would guess that if you reset your script to the way it was, and call the merlin function like this:

$= Merlin()

That it would probably work ok ...

-Shawn