Implemented new approach

Also added test cases for arrays and functions