refactored and fixed a logic error with diagonally adjacent