public int pick_victim() throws 
    BufferPoolExceededException, 
    PagePinnedException {
    
    // The current frame in the Buffer Table
    FrameDesc frame;
      
    // num is used to determine how many times we have iterated through the state array
    int num = 0;
      
    // numBuffers is the size of the state array
    int numBuffers = mgr.getNumBuffers();
      
    // Mod by the numBuffers to ensure the head (aka clock hand) is within the array 
    // NOTE: head is a member variable of replacer class
    head = ( head + 1) % numBuffers;
      
    // Iterate through the state array to find an available frame in the buffer pool
    while ( state_bit[head].state != Available ) {
        
      // On first pass, set all referenced states to available
      if ( state_bit[head].state == Referenced )
        state_bit[head].state = Available;
  
      // If you have iterated through the array twice without an available frame
      // then there are no available frames in the buffer pool. 
      if ( num == numBuffers * 2 ) 
        throw new BufferPoolExceededException (null, "CLOCK: The Buffer Pool is full.");
        
      // Increment num
      num++;
        
      // Move to the next position in the array
      head = (head+1) % numBuffers;
    } // end while
    
    // Set the current frame
    frame = (mgr.frameTable())[head];
    
    // Confirm the page is not pinned
    if (frame.pin_count() != 0) {
      throw new PagePinnedException (null, "CLOCK: Current page is still pinned");
    } // end if
      
    // Pin the current frame to ensure other processes don't try to use it
    state_bit[head].state = Pinned;        
    frame.pin();    
      
    return head;
  } // end pick_victim()