Improved state() function for array and added tests for it