Refactor check neighnor loop