i finally got it
no more eerrors with the function i did

i had to change:

Code:
		if ((cells.length < x) || (x < 0) || (cells[0].length < y) || (y < 0))
to

Code:
		if ((cells.length <= x) || (x < 0) || (cells[0].length <= y) || (y < 0))