PR #2: detection code now looks a bit better