Performance improvement for checking valid moves.