Handle circular structures more properly

It's quite confusing to get a serialisation error with circular json structures.

I've updated JSON.stringify function (copypasted from stackoverflow) and test as well.

And it's time to use tabs instead of spaces, for sure.