differentiate circular references

I would move this (and the var declaration down to where you check it), otherwise you're going to have needless indexOf's happening for strings/booleans/numbers/functions.