Fixed unregistering whilst in a loop.