I haven't tested this code, but I can tell from the part where it's appending dots that it doesn't handle array indexes. It actually might be pretty easy to fix this: instead of appending things with dots, put them in brackets! That should work for both methods of indexing.