Fixes to register function and cleanup