Added unit tests and fixed problems with deep nested arrays