Clean up the ffi imports.

Mostly just removed some unused bits, and grouped things together a bit
more logically; this could still do with more work.