Implement module_initialize and module_finalize
Improve error handling