Added summing for the array, fixed bugs