Fixed unregistering and added tests for it