finished global array version