Encodings are weird, but I think I got it now.
First try at search. Can be made more beautiful by more monoids.
small fixes
Partial merge of frontend fixes.