Support function for boxing
Implement apply

Also a bit of rearrangement, after I figured out what was meant to go
where in the C code.