Not sure what I've done wrong...

What data are you getting when you read x + 1 and/or y + 1 when x and/or y are at the array edge?