added code to handle last chunk in bytes array