added diagonals checking logic