public int readBit() throws IOException {
		int returnBit;   // Hold the bit to return
		
		if(afterNext == -1)  // Are we emptying the last byte?
			
			// When afterNext == -1, next is the count of bits remaining.
			
			if(next == 0)   // No more bits in the final byte to return
		  	return -1;    // No more bits to return
		  else {
		  	if((bitMask & current) == 0)
		  		returnBit = 0;
		  	else 
		  		returnBit = 1;
		  	
        next--;          // One fewer bit to return
        bitMask = bitMask >> 1;    // Shift to mask next bit
        return returnBit;
		  }
		else {
	  	if((bitMask & current) == 0)
	  		returnBit = 0;
	  	else 
	  		returnBit = 1;
	  	
      bitMask = bitMask >> 1;    // Shift to mask next bit
      
      if(bitMask == 0)  {        // Finished returning this byte?
      	bitMask = 128;           // Leftmost bit next
      	current = next;
      	next = afterNext;
      	afterNext = input.read();
      }
      return returnBit;
		}
	}