Fix tuple-foldl, bits-encode and add tests