Refactor init and error handling code

Move common ffi initialization code to 'ffi::init()' and the initialization of error handling to a
a shared location.