Extract init and shutdown functions

Also a 'send' function