worked out the bug on array function