Modify tranfer() to return number of transfered bytes