Handled null lists
Changed to be closer to the original version
More tests for the toStringInternal