corrected the neighbour calculation