Abstracted detection code and a test.
cleaning up test code