make it work with arrays, but it is sloooooow