Speed up the GetValidMoves function.