Fixed segm fault. Added immediate neighbour variable