         
         var attribute: Attribute {
             
-            let propertiesMask = properties.rawValue
-            let valueHandleBytes = valueHandle.littleEndian.bytes
-            let value: Data = [propertiesMask, valueHandleBytes.0, valueHandleBytes.1] + uuid.littleEndian.data
+            var data = Data(capacity: 3 + uuid.dataLength)
+            data += properties.rawValue
+            data += valueHandle.littleEndian
+            data += uuid.littleEndian
             
             return Attribute(handle: handle,
                              uuid: type(of: self).uuid,
-                             value: value,
+                             value: data,
                              permissions: [.read])
         }
         

        
        var attribute: Attribute {
            
            let handleBytes = serviceHandle.littleEndian.bytes
            
            let endGroupBytes = endGroupHandle.littleEndian.bytes
            
            let value: Data = [handleBytes.0,
                               handleBytes.1,
                               endGroupBytes.0,
                               endGroupBytes.1] + uuid.littleEndian.data
            
            return Attribute(handle: handle,
                             uuid: type(of: self).uuid,
                             value: value,
                             permissions: [.read])
        }
        

    }
}

// MARK: - Sequence

extension GATTDatabase: Sequence {
    
    public func makeIterator() -> IndexingIterator<GATTDatabase> {
        return IndexingIterator(_elements: self)
    }
}

// MARK: - Collection

extension GATTDatabase: Collection {
    
    public func index(after index: Int) -> Int {
        
        return index + 1
    }
    
    public var startIndex: Int {
        
        return 0
    }
    
    public var endIndex: Int {
        
        return count
    }
}

// MARK: - RandomAccessCollection

extension GATTDatabase: RandomAccessCollection {
    
    public subscript(bounds: Range<Int>) -> Slice<GATTDatabase> {
        
        return Slice<GATTDatabase>(base: self, bounds: bounds)
    }
}

