refactored the checking neighbours method