Limit max recursion depth when printing

Otherwise a StackOverflowException can be thrown that will terminate the
whole process.
This should be revisited and the printing process changed to not use
recursion.