Add deregister function.
Clean the code.