debugged array version