Added support for arrays
code refactoring