 
     func intFromBits(count: Int) -> Int {
         guard count > 0 else { return 0 }
+
         var result = 0
         for i in 0..<count {
-            let currentIndex: Int
             let power: Int
             switch self.bitOrder {
             case .straight:
-                currentIndex = 8 * index + bitShift
                 power = count - i - 1
             case .reversed:
-                currentIndex = 8 * (index + 1) - bitShift - 1
                 power = i
             }
 
-            result += Int(pow(Double(2), Double(power))) *
-                Int(bitPattern: UInt(CFBitVectorGetBitAtIndex(self.bitVector, currentIndex)))
+            let bit = self.bitArray[self.index] & self.bitMask > 0 ? 1 : 0
+            result += Int(pow(Double(2), Double(power))) * bit
 
-            self.bitShift += 1
-            if self.bitShift >= 8 {
-                self.bitShift = 0
-                self.index += 1
+            switch self.bitOrder {
+            case .reversed:
+                if self.bitMask == 128 {
+                    self.index += 1
+                    self.bitMask = 1
+                } else {
+                    self.bitMask <<= 1
+                }
+            case .straight:
+                if self.bitMask == 1 {
+                    self.index += 1
+                    self.bitMask = 128
+                } else {
+                    self.bitMask >>= 1
+                }
             }
         }
 


        var array: [UInt8] = Array(repeating: 0, count: count)
        for i in 0..<count {
            let currentIndex: Int
            switch self.bitOrder {
            case .straight:
                currentIndex = 8 * index + bitShift
            case .reversed:
                currentIndex = 8 * (index + 1) - bitShift - 1
            }

            array[i] = UInt8(truncatingBitPattern: CFBitVectorGetBitAtIndex(self.bitVector, currentIndex))

            self.bitShift += 1
            if self.bitShift >= 8 {
                self.bitShift = 0
                self.index += 1
            }
        }


        return self.bits(count: 1).first!
    }

    func alignedByte() -> UInt8 {
        self.skipUntilNextByte()
        self.index += 1
        return self.bitArray[self.index - 1]
    }

    // MARK: Manipulations with index and bitShift

    func skipUntilNextByte() {
        switch self.bitOrder {
        case .reversed:
            guard self.bitMask != 1 else { return }
            self.bitMask = 1
        case .straight:
            guard self.bitMask != 128 else { return }
            self.bitMask = 128
        }
        self.index += 1
    }

}
