Index: /code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.cc
===================================================================
--- /code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.cc	(revision 9485)
+++ /code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.cc	(revision 9486)
@@ -216,26 +216,24 @@
                 }
 
-                // Selected object
-                if(this->closestTarget_) {
-                    // select the closest object as target
+                // select the object that aim-assistant indicates
+                if(this->closestTarget_)
+                // select the closest object
+                {
                     if(listIt == this->sortedObjectList_.begin())
                     {
                         it->second.selected_ = true;
-                        orxout() << "Closest object selected" << std::endl;
                     }
                     else if(it->second.selected_)
                     {
                         it->second.selected_ = false;
-                        orxout() << "Previous object unselected" << std::endl;
-                    }
-
-                }
-                // select the next closest object
+                    }
+
+                }
                 else if(this->nextTarget_)
+                // select the next object in sortedObjectList
                 {
                     if(nextHasToBeSelected){
                         it->second.selected_ = true;
                         nextHasToBeSelected = false;
-                        orxout() << "Next object selected" << std::endl;
                     }
                     else if(it->second.selected_)
@@ -243,20 +241,20 @@
                         nextHasToBeSelected = true;
                         it->second.selected_ = false;
-                        orxout() << "Previous object unselected" << std::endl;
-
+
+                        // check if there's a next object
                         listIt++;
-
-                        if (markerCount + 1 >= this->markerLimit_ ||
-                                (listIt->second > this->detectionLimit_
-                                && detectionLimit_ >= 0))
-                        {
-                            this->activeObjectList_.find(this->sortedObjectList_.begin()->first)->second.selected_ = true;
-                            nextHasToBeSelected = false;
-                        }
-
+                        if(listIt != this->sortedObjectList_.end())
+                        {
+                            // and if the marker limit and max-distance are not exceeded for it
+                            if (markerCount + 1 >= this->markerLimit_ ||
+                                    (listIt->second > this->detectionLimit_ && detectionLimit_ >= 0))
+                            {
+                                // otherwise select the closest object
+                                this->activeObjectList_.find(this->sortedObjectList_.begin()->first)->second.selected_ = true;
+                                nextHasToBeSelected = false;
+                            }
+                        }
                         listIt--;
                     }
-
-
                 }
 
@@ -373,13 +371,16 @@
                             || it->first->getRVVelocity().squaredLength() == 0
                             || pawn == NULL
-                            /*|| humanPawn == NULL
-                            || pawn->getTeam() == humanPawn->getTeam()*/)
+                            /* TODO : improve getTeam in such a way that it works
+                             * || humanPawn == NULL
+                             * || pawn->getTeam() == humanPawn->getTeam()*/)
                     {
                         // don't show marker for not selected enemies nor if the selected doesn't move
                         it->second.target_->hide();
                     }
-                    else
-                    {
+                    else // object is selected and moves
+                    {
+                        // get the aim position
                         Vector3* targetPos = this->toAimPosition(it->first);
+                        // Transform to screen coordinates
                         Vector3 screenPos = camTransform * (*targetPos);
                         // Check if the target marker is in view too
@@ -395,5 +396,4 @@
                             it->second.target_->show();
                         }
-
                         delete targetPos;
                     }
