 class DataWithPointer {
 
     let bitOrder: BitOrder
-    let bitVector: CFBitVector
-    var index: Int
-    var bitShift: Int
+    private let bitArray: [UInt8]
+    var index: Int = 0
+    var bitMask: UInt8
 
     init(data: Data, bitOrder: BitOrder) {
-        self.index = 0
-        self.bitShift = 0
         self.bitOrder = bitOrder
-        self.bitVector = CFBitVectorCreate(kCFAllocatorDefault, data.toArray(type: UInt8.self), data.count * 8)
+        self.bitArray = data.toArray(type: UInt8.self)
+
+        switch self.bitOrder {
+        case .reversed:
+            self.bitMask = 1
+        case .straight:
+            self.bitMask = 128
+        }
     }
 
     func bits(count: Int) -> [UInt8] {


    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)))

            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
    }

}
