@Override
    public void onMessage(Message msg) {
        if (working){
        Object message = msg.content;
        if (message instanceof SearchMessage) 
        {
            SearchMessage sm = (SearchMessage) message;
            SensorSearchMessage ssm = new SensorSearchMessage(sm.getLocation(), id, myPosition);
            ssm.getEvl().addAll(evl);
            send(null, ssm);
        }
        if (message instanceof SensorSearchMessage) {
            SensorSearchMessage ssm = (SensorSearchMessage) message;
            if (isBorderNode()) { // Border node
                if (!receivedMessages.contains(ssm)){
                    SensorSearchMessage sensorSearchMessage = new SensorSearchMessage(ssm.getPosition(), id, myPosition);
                    sensorSearchMessage.getEvl().addAll(evl);
                    sensorSearchMessage.getEvl().addAll(ssm.getEvl());
                    send(null, sensorSearchMessage);
                } else {
                    Coordinate c = ssm.getEvl().iterator().next();
                    SearchResultMessage srm = new SearchResultMessage(c);
                    send(null,srm);
                }
            }
            receivedMessages.add(ssm);
        }
        if (message instanceof FailureMessage){
            FailureMessage fm = (FailureMessage) message;
            if (isBorderNode()){
                evl.add(fm.getPosition());
            }
            if (!receivedFailureMessages.contains(fm)){
                send(null,new FailureMessage(fm.getPosition(), myPosition));
            }
            receivedFailureMessages.add(fm);
        }
        if (message instanceof HelloMessage) {
            HelloMessage hm = (HelloMessage) message;
            neighbours.put(hm.getPosition(), 0);
        }
        }
    }