need to copy array as unregister modifies it