Fixed bug in array calculations