Detection code added. It has bugs..

Detection code added. It has bugs..