Reorganized device detection code

Multiple successive calls to callback registering should now be possible