working, stack-safe version of toReprJS