Cleanup and added tests for expand/collapse array and function