diff --git a/HPi.cabal b/HPi.cabal
--- a/HPi.cabal
+++ b/HPi.cabal
@@ -2,7 +2,7 @@
 -- see http://haskell.org/cabal/users-guide/
 
 name:                HPi
-version:             0.5.0
+version:             0.5.1
 synopsis:            GPIO, I2C and SPI functions for the Raspberry Pi.
 description:         This package is a FFI wrapper around the bcm2835 library by Mike McCauley, it also includes a few utility functions for easier use of the imported functions.
 homepage:            https://github.com/WJWH/HPi
@@ -19,6 +19,7 @@
   exposed-modules:     System.RaspberryPi.GPIO
   -- other-modules:       
   build-depends:    base < 5, bytestring < 0.11
+  extra-libraries: bcm2835
   
 source-repository head
   type:     git
diff --git a/System/RaspberryPi/GPIO.hs b/System/RaspberryPi/GPIO.hs
--- a/System/RaspberryPi/GPIO.hs
+++ b/System/RaspberryPi/GPIO.hs
@@ -171,13 +171,13 @@
                         stopSPI
                         f
                         
--- Possible error results for I2C functions.
-actOnResult :: CUChar -> CString -> IO BS.ByteString
+-- Possible error results for I2C functions. (not exported)
+actOnResult :: CUChar -> CStringLen -> IO BS.ByteString
 actOnResult rr buf = case rr of
     0x01 -> throwIO $ IOError Nothing IllegalOperation "I2C: " "Received an unexpected NACK." Nothing Nothing
     0x02 -> throwIO $ IOError Nothing IllegalOperation "I2C: " "Received Clock Stretch Timeout." Nothing Nothing 
     0x04 -> throwIO $ IOError Nothing IllegalOperation "I2C: " "Not all data was read." Nothing Nothing
-    0x00 -> BS.packCString buf --convert C buffer to a bytestring
+    0x00 -> BS.packCStringLen buf --convert C buffer to a bytestring
 
 
 -- Mapping raspberry pi pin number to internal bmc2835 pin number, ugly solution, but meh. Also, the existence of mutiple versions
@@ -255,9 +255,9 @@
 
 -- |Writes the data in the 'ByteString' to the specified I2C 'Address'. Throws an IOException if an error occurs.
 writeI2C :: Address -> BS.ByteString -> IO ()	--writes a bytestring to the specified address
-writeI2C address by = BS.useAsCString by $ \bs -> do
+writeI2C address by = BS.useAsCStringLen by $ \(bs,len) -> do
     setI2cAddress address
-    readresult <- c_writeI2C bs (fromIntegral $ BS.length by)
+    readresult <- c_writeI2C bs (fromIntegral len)
     case readresult of
         0x01 -> throwIO $ IOError Nothing IllegalOperation "I2C: " "Received an unexpected NACK." Nothing Nothing
         0x02 -> throwIO $ IOError Nothing IllegalOperation "I2C: " "Received Clock Stretch Timeout." Nothing Nothing 
@@ -269,16 +269,16 @@
 readI2C address num = allocaBytes (num+1) $ \buf -> do --is the +1 necessary??
     setI2cAddress address
     readresult <- c_readI2C buf (fromIntegral num)
-    actOnResult readresult buf
+    actOnResult readresult (buf, num)
 
 -- |Writes the data in the 'ByteString' to the specified 'Address', then issues a "repeated start" (with no prior stop) and then 
 -- reads num bytes from the same 'Address'. Necessary for devices that require such behavior, such as the MLX90620.
 writeReadRSI2C :: Address -> BS.ByteString -> Int -> IO BS.ByteString
-writeReadRSI2C address by num = BS.useAsCString by $ \bs -> do --marshall the register-containing bytestring
-    allocaBytes (num+1) $ \buf -> do	--allocate a buffer for the response
+writeReadRSI2C address by num = BS.useAsCStringLen by $ \(bs,len) -> do --marshall the register-containing bytestring
+    allocaBytes num $ \buf -> do	--allocate a buffer for the response
         setI2cAddress address
-        readresult <- c_writeReadRSI2C bs (fromIntegral $ BS.length by) buf (fromIntegral num)
-        actOnResult readresult buf
+        readresult <- c_writeReadRSI2C bs (fromIntegral len) buf (fromIntegral num)
+        actOnResult readresult (buf, num)
         
 -------------------------------------------- SPI functions -------------------------------------------------------------------------
 -- |Sets the chip select pin(s). When a transfer is made with 'transferSPI' or 'transferManySPI', the selected pin(s) will be 
