Changed bytes to Math.floor so desired length is never exceeded.