Added toString function, fixed bugs when generating record tree