Fixed bug with nested tuples, added some tests, implemented nested tuple optimization.