anchor.diff:          |> Set.ofSeq
             
   
  -    let bfs graph (source: VertexId) : BFS = 
  -        
  +    /// Run a breadth first search on the graph from a source vertex
  +    let breadthFirstSearch graph (source: VertexId) : GraphResult<BFS> = 
  +        
  +        // Start of only knowing the distance to the source vertex. Every other vertex is unprocessed - None.
           let distances = Array.create (graph.VerticesCount + 1) None
           let pathTree = Array.create (graph.VerticesCount + 1) None
           distances.[source.Id] <- Some(Distance 0u)
           let q = new Queue<VertexId>(seq { yield source })  
   
  +        /// Increment a distance value
           let stepDistance (dist: Distance option): Distance option = 
               match dist with 
               | Some(d) -> Some (Distance <| d.Distance + 1u)
               | None -> failwith "Algorithm error, distance to previous point in path should not be None."
               
  -        while q.Count > 0 do 
  -            let vId = q.Dequeue()
  -            let vertex = vertexFromId graph vId
  -            for neighbourId in vertex.Neighbours do 
  -                if distances.[neighbourId.Id].IsNone then
  -                    q.Enqueue(neighbourId)
  -                    let neighbourIndex = neighbourId.Id
  -                    let vIndex = vId.Id
  -                    distances.[neighbourIndex] <- stepDistance distances.[vIndex]
  -                    pathTree.[neighbourIndex] <- Some(vId)
  -                    
  -        {Source = source
  -         ShortestPathDistances = distances
  -         ShortestPathTree = pathTree}
  +        trial {
  +            while q.Count > 0 do 
  +                let vId = q.Dequeue()
  +                let! vertex = vertexFromId graph vId
  +                for neighbourId in vertex.Neighbours do 
  +                    if distances.[neighbourId.Id].IsNone then
  +                        q.Enqueue(neighbourId)
  +                        let neighbourIndex = neighbourId.Id
  +                        let vIndex = vId.Id
  +                        distances.[neighbourIndex] <- stepDistance distances.[vIndex]
  +                        pathTree.[neighbourIndex] <- Some(vId)
  +            
  +            return         
  +                {Source = source
  +                 ShortestPathDistances = distances
  +                 ShortestPathTree = pathTree}
  +        }
        
       
       /// Return the shortest path from a source vertex defined by the bfsData to a destination vertex
  
positive.code:         else
              None
  
      let isBipartite graph =
          // Its vertices can be split into two parts such that each edge of the
          // graph joins to vertices from different parts
          // In other words, a graph is bipartite if its vertices can be colored with two colors
          // (say, black and white) such that the endpoints of each edge have different colors. 
  
          // Run BFS and store the colour of each vertex as we go along, changing it on each edge
          // traversal. If the colour is already set and does not match the expected colour coming
          // out of another vertex then it isn't bipartite.
  
negative.code:             | Green -> Red
              | Uncoloured -> Uncoloured
  
          trial {                        
              let mutable failedTwoColouring = false
              while q.Count > 0 && not failedTwoColouring do
                  
                  let vId = q.Dequeue()
                  let vIndex = vId.Id
                  let vColour = twoColourings.[vIndex]
                  let requiredNeighboursColour = oppositeColour vColour
                  
                  let! vertex = vertexFromId graph vId
                  
                  for neighbourId in vertex.Neighbours do 
                      let neighbourIndex = neighbourId.Id
                      let neighbourColour = twoColourings.[neighbourIndex]
                      match neighbourColour with 
                      | Uncoloured ->
                          q.Enqueue(neighbourId)
                          twoColourings.[neighbourIndex] <- requiredNeighboursColour
                      | _ -> if neighbourColour <> requiredNeighboursColour then
                                  failedTwoColouring <- true           
  
              return (not failedTwoColouring)
          }
  