diff --git a/geometry/Building.cpp b/geometry/Building.cpp
index 669cf4a7364bffbe3616ede5cdab3bd1be7dfa3a..462f31270a11fb5555ead30dc495246da1751266 100644
--- a/geometry/Building.cpp
+++ b/geometry/Building.cpp
@@ -32,11 +32,13 @@
 #include "../tinyxml/tinyxml.h"
 
 #ifdef _SIMULATOR
+
 #include "../pedestrian/Pedestrian.h"
 #include "../mpi/LCGrid.h"
 #include "../routing/SafestPathRouter.h"
 #include "../routing/RoutingEngine.h"
 #include "../pedestrian/PedDistributor.h"
+
 #endif
 
 //#undef _OPENMP
@@ -50,88 +52,80 @@
 
 using namespace std;
 
-
 Building::Building()
 {
      _caption = "no_caption";
      _projectFilename = "";
-     _geometryFilename= "";
+     _geometryFilename = "";
      _routingEngine = nullptr;
      _linkedCellGrid = nullptr;
      _savePathway = false;
 }
 
 #ifdef _SIMULATOR
-Building::Building(const std::string& filename, const std::string& rootDir, RoutingEngine& engine, PedDistributor& distributor, double linkedCellSize)
-:_projectFilename(filename), _projectRootDir(rootDir), _routingEngine(&engine)
+
+Building::Building(const std::string& filename, const std::string& rootDir, RoutingEngine& engine,
+        PedDistributor& distributor, double linkedCellSize)
+        :_projectFilename(filename), _projectRootDir(rootDir), _routingEngine(&engine)
 {
      _caption = "no_caption";
      _savePathway = false;
      _linkedCellGrid = nullptr;
 
      //todo: what happens if any of these  methods failed (return false)? throw exception ?
-     if(!LoadGeometry())
-     {
+     if (!LoadGeometry()) {
           Log->Write("ERROR:\t could not load the geometry!");
-          exit (EXIT_FAILURE);
+          exit(EXIT_FAILURE);
      }
 
-
-
-     if(!LoadRoutingInfo(filename))
-     {
+     if (!LoadRoutingInfo(filename)) {
           Log->Write("ERROR:\t could not load extra routing information!");
-          exit (EXIT_FAILURE);
+          exit(EXIT_FAILURE);
      }
 
      //this->AddSurroundingRoom();
 
-     if(!InitGeometry())
-     {
+     if (!InitGeometry()) {
           Log->Write("ERROR:\t could not initialize the geometry!");
-          exit (EXIT_FAILURE);
+          exit(EXIT_FAILURE);
      }
-     for(auto& room : _rooms) {
+     for (auto& room : _rooms) {
           auto& subs = room.second->GetAllSubRooms();
-          for(auto& sub : subs) {
+          for (auto& sub : subs) {
                _allSubRooms.push_back(sub.second.get());
           }
      }
 
      //triangulate the geometry
-     if(!Triangulate())
-     {
+     if (!Triangulate()) {
           Log->Write("ERROR:\t could not triangulate the geometry!");
-          exit (EXIT_FAILURE);
+          exit(EXIT_FAILURE);
      }
 
-     if(!LoadTrafficInfo() )
-     {
+     if (!LoadTrafficInfo()) {
           Log->Write("ERROR:\t could not load extra traffic information!");
-          exit (EXIT_FAILURE);
+          exit(EXIT_FAILURE);
      }
 
-     if(!distributor.Distribute(this))
-     {
+     if (!distributor.Distribute(this)) {
           Log->Write("ERROR:\t could not distribute the pedestrians");
-          exit (EXIT_FAILURE);
+          exit(EXIT_FAILURE);
      }
 
      InitGrid(linkedCellSize);
 
-     if(! _routingEngine->Init(this))
-     {
+     if (!_routingEngine->Init(this)) {
           Log->Write("ERROR:\t could not initialize the routers!");
-          exit (EXIT_FAILURE);
+          exit(EXIT_FAILURE);
      }
 
-     if(!SanityCheck())
-     {
+     if (!SanityCheck()) {
           Log->Write("ERROR:\t There are sanity errors in the geometry file");
-          exit (EXIT_FAILURE);
+          exit(EXIT_FAILURE);
      }
 
 }
+
 #endif
 
 Building::~Building()
@@ -141,8 +135,7 @@ Building::~Building()
      //    delete _rooms[i];
 
 #ifdef _SIMULATOR
-     for(unsigned int p=0;p<_allPedestians.size();p++)
-     {
+     for (unsigned int p = 0; p<_allPedestians.size(); p++) {
           delete _allPedestians[p];
      }
      _allPedestians.clear();
@@ -152,21 +145,20 @@ Building::~Building()
      if (_pathWayStream.is_open())
           _pathWayStream.close();
 
-
      for (map<int, Crossing*>::const_iterator iter = _crossings.begin();
-               iter != _crossings.end(); ++iter) {
+          iter!=_crossings.end(); ++iter) {
           delete iter->second;
      }
      for (map<int, Transition*>::const_iterator iter = _transitions.begin();
-               iter != _transitions.end(); ++iter) {
+          iter!=_transitions.end(); ++iter) {
           delete iter->second;
      }
      for (map<int, Hline*>::const_iterator iter = _hLines.begin();
-               iter != _hLines.end(); ++iter) {
+          iter!=_hLines.end(); ++iter) {
           delete iter->second;
      }
      for (map<int, Goal*>::const_iterator iter = _goals.begin();
-               iter != _goals.end(); ++iter) {
+          iter!=_goals.end(); ++iter) {
           delete iter->second;
      }
 }
@@ -205,7 +197,7 @@ int Building::GetNumberOfRooms() const
 
 int Building::GetNumberOfGoals() const
 {
-     return _transitions.size() + _hLines.size() + _crossings.size();
+     return _transitions.size()+_hLines.size()+_crossings.size();
 }
 
 const std::map<int, std::unique_ptr<Room> >& Building::GetAllRooms() const
@@ -216,9 +208,8 @@ const std::map<int, std::unique_ptr<Room> >& Building::GetAllRooms() const
 Room* Building::GetRoom(int index) const
 {
      //todo: obsolete since the check is done by .at()
-     if(_rooms.count(index)==0)
-     {
-          Log->Write("ERROR: Wrong 'index' in CBuiling::GetRoom() Room ID: %d size: %d",index, _rooms.size());
+     if (_rooms.count(index)==0) {
+          Log->Write("ERROR: Wrong 'index' in CBuiling::GetRoom() Room ID: %d size: %d", index, _rooms.size());
           Log->Write("\tControl your rooms ID and make sure they are in the order 0, 1, 2,.. ");
           return nullptr;
      }
@@ -226,7 +217,6 @@ Room* Building::GetRoom(int index) const
      return _rooms.at(index).get();
 }
 
-
 LCGrid* Building::GetGrid() const
 {
      return _linkedCellGrid;
@@ -234,67 +224,57 @@ LCGrid* Building::GetGrid() const
 
 void Building::AddRoom(Room* room)
 {
-     _rooms[room->GetID()]=std::unique_ptr<Room>(room);
+     _rooms[room->GetID()] = std::unique_ptr<Room>(room);
 }
 
 bool Building::InitGeometry()
 {
      Log->Write("INFO: \tInit Geometry");
 
-     for(auto&& itr_room: _rooms)
-     {
-          for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
-          {
+     for (auto&& itr_room: _rooms) {
+          for (auto&& itr_subroom: itr_room.second->GetAllSubRooms()) {
                //create a close polyline out of everything
                vector<Line*> goals = vector<Line*>();
 
                //  collect all crossings
-               for(auto&& cros:itr_subroom.second->GetAllCrossings())
-               {
+               for (auto&& cros:itr_subroom.second->GetAllCrossings()) {
                     goals.push_back(cros);
                }
                //collect all transitions
-               for(auto&& trans:itr_subroom.second->GetAllTransitions())
-               {
+               for (auto&& trans:itr_subroom.second->GetAllTransitions()) {
                     goals.push_back(trans);
                }
                // initialize the poly
-               if(! itr_subroom.second->ConvertLineToPoly(goals))
+               if (!itr_subroom.second->ConvertLineToPoly(goals))
                     return false;
                itr_subroom.second->CalculateArea();
 
                //do the same for the obstacles that are closed
-               for(auto&& obst:itr_subroom.second->GetAllObstacles())
-               {
+               for (auto&& obst:itr_subroom.second->GetAllObstacles()) {
                     //if (obst->GetClosed() == 1)
-                    if(!obst->ConvertLineToPoly())
+                    if (!obst->ConvertLineToPoly())
                          return false;
                }
                double minElevation = 1000;
                double maxElevation = -1000;
-               for(auto && wall:itr_subroom.second->GetAllWalls())
-               {
-                     Point P1 = wall.GetPoint1();
-                     Point P2 = wall.GetPoint2();
-                     if(minElevation > itr_subroom.second->GetElevation(P1))
-                     {
-                           minElevation = itr_subroom.second->GetElevation(P1);
-                     }
-                
-                     if(maxElevation < itr_subroom.second->GetElevation(P1))
-                     {
-                           maxElevation = itr_subroom.second->GetElevation(P1);
-                     }
-                
-                     if(minElevation > itr_subroom.second->GetElevation(P2))
-                     {
-                           minElevation = itr_subroom.second->GetElevation(P2);
-                     }
-                
-                     if(maxElevation < itr_subroom.second->GetElevation(P2))
-                     {
-                           maxElevation = itr_subroom.second->GetElevation(P2);
-                     }          
+               for (auto&& wall:itr_subroom.second->GetAllWalls()) {
+                    Point P1 = wall.GetPoint1();
+                    Point P2 = wall.GetPoint2();
+                    if (minElevation>itr_subroom.second->GetElevation(P1)) {
+                         minElevation = itr_subroom.second->GetElevation(P1);
+                    }
+
+                    if (maxElevation<itr_subroom.second->GetElevation(P1)) {
+                         maxElevation = itr_subroom.second->GetElevation(P1);
+                    }
+
+                    if (minElevation>itr_subroom.second->GetElevation(P2)) {
+                         minElevation = itr_subroom.second->GetElevation(P2);
+                    }
+
+                    if (maxElevation<itr_subroom.second->GetElevation(P2)) {
+                         maxElevation = itr_subroom.second->GetElevation(P2);
+                    }
                }
                itr_subroom.second->SetMaxElevation(maxElevation);
                itr_subroom.second->SetMinElevation(minElevation);
@@ -305,20 +285,18 @@ bool Building::InitGeometry()
      // look and save the neighbor subroom for improving the runtime
      // that information is already present in the crossing/transitions
 
-     for(const auto & cross: _crossings)
-     {
-          SubRoom* s1=cross.second->GetSubRoom1();
-          SubRoom* s2=cross.second->GetSubRoom2();
-          if(s1) s1->AddNeighbor(s2);
-          if(s2) s2->AddNeighbor(s1);
+     for (const auto& cross: _crossings) {
+          SubRoom* s1 = cross.second->GetSubRoom1();
+          SubRoom* s2 = cross.second->GetSubRoom2();
+          if (s1) s1->AddNeighbor(s2);
+          if (s2) s2->AddNeighbor(s1);
      }
 
-     for(const auto & trans: _transitions)
-     {
-          SubRoom* s1=trans.second->GetSubRoom1();
-          SubRoom* s2=trans.second->GetSubRoom2();
-          if(s1) s1->AddNeighbor(s2);
-          if(s2) s2->AddNeighbor(s1);
+     for (const auto& trans: _transitions) {
+          SubRoom* s1 = trans.second->GetSubRoom1();
+          SubRoom* s2 = trans.second->GetSubRoom2();
+          if (s1) s1->AddNeighbor(s2);
+          if (s2) s2->AddNeighbor(s1);
      }
 
      Log->Write("INFO: \tInit Geometry successful!!!\n");
@@ -326,38 +304,37 @@ bool Building::InitGeometry()
      return true;
 }
 
-
 const string& Building::GetProjectFilename() const
 {
      return _projectFilename;
 }
 
-void Building::SetProjectFilename(const std::string &filename)
+void Building::SetProjectFilename(const std::string& filename)
 {
-     _projectFilename=filename;
+     _projectFilename = filename;
 }
 
-void Building::SetProjectRootDir(const std::string &filename)
+void Building::SetProjectRootDir(const std::string& filename)
 {
-     _projectRootDir= filename;
+     _projectRootDir = filename;
 }
 
 const string& Building::GetProjectRootDir() const
 {
      return _projectRootDir;
 }
+
 const std::string& Building::GetGeometryFilename() const
 {
      return _geometryFilename;
 }
 
-bool Building::LoadGeometry(const std::string &geometryfile)
+bool Building::LoadGeometry(const std::string& geometryfile)
 {
      //get the geometry filename from the project file
-     string geoFilenameWithPath= _projectRootDir + geometryfile;
+     string geoFilenameWithPath = _projectRootDir+geometryfile;
 
-     if(geometryfile=="")
-     {
+     if (geometryfile=="") {
           TiXmlDocument doc(_projectFilename);
           if (!doc.LoadFile()) {
                Log->Write("ERROR: \t%s", doc.ErrorDesc());
@@ -368,9 +345,9 @@ bool Building::LoadGeometry(const std::string &geometryfile)
           Log->Write("INFO: \tParsing the geometry file");
           TiXmlElement* xMainNode = doc.RootElement();
 
-          if(xMainNode->FirstChild("geometry")) {
-               _geometryFilename=xMainNode->FirstChild("geometry")->FirstChild()->Value();
-               geoFilenameWithPath=_projectRootDir+_geometryFilename;
+          if (xMainNode->FirstChild("geometry")) {
+               _geometryFilename = xMainNode->FirstChild("geometry")->FirstChild()->Value();
+               geoFilenameWithPath = _projectRootDir+_geometryFilename;
                Log->Write("INFO: \tgeometry <"+_geometryFilename+">");
           }
      }
@@ -383,27 +360,27 @@ bool Building::LoadGeometry(const std::string &geometryfile)
      }
 
      TiXmlElement* xRootNode = docGeo.RootElement();
-     if( ! xRootNode ) {
+     if (!xRootNode) {
           Log->Write("ERROR:\tRoot element does not exist");
           return false;
      }
 
-     if( xRootNode->ValueStr () != "geometry" ) {
+     if (xRootNode->ValueStr()!="geometry") {
           Log->Write("ERROR:\tRoot element value is not 'geometry'.");
           return false;
      }
-     if(xRootNode->Attribute("unit"))
-          if(string(xRootNode->Attribute("unit")) != "m") {
-               Log->Write("ERROR:\tOnly the unit m (meters) is supported. \n\tYou supplied [%s]",xRootNode->Attribute("unit"));
-               return false;
-          }
+     if (xRootNode->Attribute("unit")) if (string(xRootNode->Attribute("unit"))!="m") {
+          Log->Write("ERROR:\tOnly the unit m (meters) is supported. \n\tYou supplied [%s]",
+                  xRootNode->Attribute("unit"));
+          return false;
+     }
 
      double version = xmltof(xRootNode->Attribute("version"), -1);
 
-     if (version != std::stod(JPS_VERSION) && version != std::stod(JPS_OLD_VERSION)) {
+     if (version!=std::stod(JPS_VERSION) && version!=std::stod(JPS_OLD_VERSION)) {
           Log->Write(" \tWrong geometry version!");
-          Log->Write(" \tOnly version >= %s supported",JPS_VERSION);
-          Log->Write(" \tPlease update the version of your geometry file to %s",JPS_VERSION);
+          Log->Write(" \tOnly version >= %s supported", JPS_VERSION);
+          Log->Write(" \tPlease update the version of your geometry file to %s", JPS_VERSION);
           return false;
      }
 
@@ -412,14 +389,14 @@ bool Building::LoadGeometry(const std::string &geometryfile)
      //<rooms> and <transitions>
 
      //processing the rooms node
-     TiXmlNode*  xRoomsNode = xRootNode->FirstChild("rooms");
+     TiXmlNode* xRoomsNode = xRootNode->FirstChild("rooms");
      if (!xRoomsNode) {
           Log->Write("ERROR: \tThe geometry should have at least one room and one subroom");
           return false;
      }
 
-     for(TiXmlElement* xRoom = xRoomsNode->FirstChildElement("room"); xRoom;
-               xRoom = xRoom->NextSiblingElement("room")) {
+     for (TiXmlElement* xRoom = xRoomsNode->FirstChildElement("room"); xRoom;
+          xRoom = xRoom->NextSiblingElement("room")) {
 
           Room* room = new Room();
           //make_unique<Song>
@@ -427,9 +404,9 @@ bool Building::LoadGeometry(const std::string &geometryfile)
           string room_id = xmltoa(xRoom->Attribute("id"), "-1");
           room->SetID(xmltoi(room_id.c_str(), -1));
 
-          string caption = "room " + room_id;
+          string caption = "room "+room_id;
           room->SetCaption(
-                    xmltoa(xRoom->Attribute("caption"), caption.c_str()));
+                  xmltoa(xRoom->Attribute("caption"), caption.c_str()));
 
           double position = xmltof(xRoom->Attribute("zpos"), 0.0);
 
@@ -440,13 +417,12 @@ bool Building::LoadGeometry(const std::string &geometryfile)
           //processing the rooms node
           //TiXmlNode*  xSubroomsNode = xRoom->FirstChild("subroom");
 
-          for(TiXmlElement* xSubRoom = xRoom->FirstChildElement("subroom"); xSubRoom;
-                    xSubRoom = xSubRoom->NextSiblingElement("subroom")) {
-
+          for (TiXmlElement* xSubRoom = xRoom->FirstChildElement("subroom"); xSubRoom;
+               xSubRoom = xSubRoom->NextSiblingElement("subroom")) {
 
                string subroom_id = xmltoa(xSubRoom->Attribute("id"), "-1");
                string SubroomClosed = xmltoa(xSubRoom->Attribute("closed"), "0");
-               string type = xmltoa(xSubRoom->Attribute("class"),"subroom");
+               string type = xmltoa(xSubRoom->Attribute("class"), "subroom");
 
                //get the equation of the plane if any
                double A_x = xmltof(xSubRoom->Attribute("A_x"), 0.0);
@@ -458,39 +434,40 @@ bool Building::LoadGeometry(const std::string &geometryfile)
 
                SubRoom* subroom = NULL;
 
-               if (type == "stair" || type == "escalator" || type == "idle_escalator") {
-                    if(xSubRoom->FirstChildElement("up")==NULL) {
-                         Log->Write("ERROR:\t the attribute <up> and <down> are missing for the " + type);
+               if (type=="stair" || type=="escalator" || type=="idle_escalator") {
+                    if (xSubRoom->FirstChildElement("up")==NULL) {
+                         Log->Write("ERROR:\t the attribute <up> and <down> are missing for the "+type);
                          Log->Write("ERROR:\t check your geometry file");
                          return false;
                     }
-                    double up_x = xmltof( xSubRoom->FirstChildElement("up")->Attribute("px"), 0.0);
-                    double up_y = xmltof( xSubRoom->FirstChildElement("up")->Attribute("py"), 0.0);
-                    double down_x = xmltof( xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
-                    double down_y = xmltof( xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
+                    double up_x = xmltof(xSubRoom->FirstChildElement("up")->Attribute("px"), 0.0);
+                    double up_y = xmltof(xSubRoom->FirstChildElement("up")->Attribute("py"), 0.0);
+                    double down_x = xmltof(xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
+                    double down_y = xmltof(xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
                     subroom = new Stair();
-                    ((Stair*)subroom)->SetUp(Point(up_x,up_y));
-                    ((Stair*)subroom)->SetDown(Point(down_x,down_y));
-               } else {
+                    ((Stair*) subroom)->SetUp(Point(up_x, up_y));
+                    ((Stair*) subroom)->SetDown(Point(down_x, down_y));
+               }
+               else {
                     //normal subroom or corridor
                     subroom = new NormalSubRoom();
                }
 
                subroom->SetType(type);
-               subroom->SetPlanEquation(A_x,B_y,C_z);
+               subroom->SetPlanEquation(A_x, B_y, C_z);
                subroom->SetRoomID(room->GetID());
                subroom->SetSubRoomID(xmltoi(subroom_id.c_str(), -1));
 
                //static int p_id=1;
                //cout<<endl<<"wall polygon: "<< p_id++<<endl;
                //looking for polygons (walls)
-               for(TiXmlElement* xPolyVertices = xSubRoom->FirstChildElement("polygon"); xPolyVertices;
-                         xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {
+               for (TiXmlElement* xPolyVertices = xSubRoom->FirstChildElement("polygon"); xPolyVertices;
+                    xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {
 
                     for (TiXmlElement* xVertex = xPolyVertices->FirstChildElement(
-                              "vertex");
-                              xVertex && xVertex != xPolyVertices->LastChild("vertex");
-                              xVertex = xVertex->NextSiblingElement("vertex")) {
+                            "vertex");
+                         xVertex && xVertex!=xPolyVertices->LastChild("vertex");
+                         xVertex = xVertex->NextSiblingElement("vertex")) {
 
                          double x1 = xmltof(xVertex->Attribute("px"));
                          double y1 = xmltof(xVertex->Attribute("py"));
@@ -503,13 +480,13 @@ bool Building::LoadGeometry(const std::string &geometryfile)
                }
 
                //looking for obstacles
-               for(TiXmlElement* xObstacle = xSubRoom->FirstChildElement("obstacle"); xObstacle;
-                         xObstacle = xObstacle->NextSiblingElement("obstacle")) {
+               for (TiXmlElement* xObstacle = xSubRoom->FirstChildElement("obstacle"); xObstacle;
+                    xObstacle = xObstacle->NextSiblingElement("obstacle")) {
 
                     int id = xmltof(xObstacle->Attribute("id"), -1);
                     int height = xmltof(xObstacle->Attribute("height"), 0);
                     //double ObstClosed = xmltof(xObstacle->Attribute("closed"), 0);
-                    string ObstCaption = xmltoa(xObstacle->Attribute("caption"),"-1");
+                    string ObstCaption = xmltoa(xObstacle->Attribute("caption"), "-1");
 
                     Obstacle* obstacle = new Obstacle();
                     obstacle->SetId(id);
@@ -518,13 +495,13 @@ bool Building::LoadGeometry(const std::string &geometryfile)
                     obstacle->SetHeight(height);
 
                     //looking for polygons (walls)
-                    for(TiXmlElement* xPolyVertices = xObstacle->FirstChildElement("polygon"); xPolyVertices;
-                              xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {
+                    for (TiXmlElement* xPolyVertices = xObstacle->FirstChildElement("polygon"); xPolyVertices;
+                         xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {
 
                          for (TiXmlElement* xVertex = xPolyVertices->FirstChildElement(
-                                   "vertex");
-                                   xVertex && xVertex != xPolyVertices->LastChild("vertex");
-                                   xVertex = xVertex->NextSiblingElement("vertex")) {
+                                 "vertex");
+                              xVertex && xVertex!=xPolyVertices->LastChild("vertex");
+                              xVertex = xVertex->NextSiblingElement("vertex")) {
 
                               double x1 = xmltof(xVertex->Attribute("px"));
                               double y1 = xmltof(xVertex->Attribute("py"));
@@ -539,19 +516,19 @@ bool Building::LoadGeometry(const std::string &geometryfile)
           }
 
           //parsing the crossings
-          TiXmlNode*  xCrossingsNode = xRoom->FirstChild("crossings");
-          if(xCrossingsNode)
-               for(TiXmlElement* xCrossing = xCrossingsNode->FirstChildElement("crossing"); xCrossing;
-                         xCrossing = xCrossing->NextSiblingElement("crossing")) {
+          TiXmlNode* xCrossingsNode = xRoom->FirstChild("crossings");
+          if (xCrossingsNode)
+               for (TiXmlElement* xCrossing = xCrossingsNode->FirstChildElement("crossing"); xCrossing;
+                    xCrossing = xCrossing->NextSiblingElement("crossing")) {
 
                     int id = xmltoi(xCrossing->Attribute("id"), -1);
                     int sub1_id = xmltoi(xCrossing->Attribute("subroom1_id"), -1);
                     int sub2_id = xmltoi(xCrossing->Attribute("subroom2_id"), -1);
 
-                    double x1 = xmltof(     xCrossing->FirstChildElement("vertex")->Attribute("px"));
-                    double y1 = xmltof(     xCrossing->FirstChildElement("vertex")->Attribute("py"));
-                    double x2 = xmltof(     xCrossing->LastChild("vertex")->ToElement()->Attribute("px"));
-                    double y2 = xmltof(     xCrossing->LastChild("vertex")->ToElement()->Attribute("py"));
+                    double x1 = xmltof(xCrossing->FirstChildElement("vertex")->Attribute("px"));
+                    double y1 = xmltof(xCrossing->FirstChildElement("vertex")->Attribute("py"));
+                    double x2 = xmltof(xCrossing->LastChild("vertex")->ToElement()->Attribute("px"));
+                    double y2 = xmltof(xCrossing->LastChild("vertex")->ToElement()->Attribute("py"));
 
                     Crossing* c = new Crossing();
                     c->SetID(id);
@@ -572,10 +549,10 @@ bool Building::LoadGeometry(const std::string &geometryfile)
      //exit(0);
 
      // all rooms are read, now proceed with transitions
-     TiXmlNode*  xTransNode = xRootNode->FirstChild("transitions");
-     if(xTransNode)
-          for(TiXmlElement* xTrans = xTransNode->FirstChildElement("transition"); xTrans;
-                    xTrans = xTrans->NextSiblingElement("transition")) {
+     TiXmlNode* xTransNode = xRootNode->FirstChild("transitions");
+     if (xTransNode)
+          for (TiXmlElement* xTrans = xTransNode->FirstChildElement("transition"); xTrans;
+               xTrans = xTrans->NextSiblingElement("transition")) {
 
                int id = xmltoi(xTrans->Attribute("id"), -1);
                // string caption = "door " + id;
@@ -588,12 +565,11 @@ bool Building::LoadGeometry(const std::string &geometryfile)
                int subroom2_id = xmltoi(xTrans->Attribute("subroom2_id"), -1);
                string type = xmltoa(xTrans->Attribute("type"), "normal");
 
-               double x1 = xmltof(     xTrans->FirstChildElement("vertex")->Attribute("px"));
-               double y1 = xmltof(     xTrans->FirstChildElement("vertex")->Attribute("py"));
-
-               double x2 = xmltof(     xTrans->LastChild("vertex")->ToElement()->Attribute("px"));
-               double y2 = xmltof(     xTrans->LastChild("vertex")->ToElement()->Attribute("py"));
+               double x1 = xmltof(xTrans->FirstChildElement("vertex")->Attribute("px"));
+               double y1 = xmltof(xTrans->FirstChildElement("vertex")->Attribute("py"));
 
+               double x2 = xmltof(xTrans->LastChild("vertex")->ToElement()->Attribute("px"));
+               double y2 = xmltof(xTrans->LastChild("vertex")->ToElement()->Attribute("py"));
 
                Transition* t = new Transition();
                t->SetID(id);
@@ -602,7 +578,7 @@ bool Building::LoadGeometry(const std::string &geometryfile)
                t->SetPoint2(Point(x2, y2));
                t->SetType(type);
 
-               if (room1_id != -1 && subroom1_id != -1) {
+               if (room1_id!=-1 && subroom1_id!=-1) {
                     //Room* room = _rooms[room1_id];
                     Room* room = GetRoom(room1_id);
                     SubRoom* subroom = room->GetSubRoom(subroom1_id);
@@ -616,7 +592,7 @@ bool Building::LoadGeometry(const std::string &geometryfile)
                     //new implementation
                     subroom->AddTransition(t);
                }
-               if (room2_id != -1 && subroom2_id != -1) {
+               if (room2_id!=-1 && subroom2_id!=-1) {
                     auto&& room = _rooms[room2_id];
                     SubRoom* subroom = room->GetSubRoom(subroom2_id);
                     //subroom->AddGoalID(t->GetUniqueID());
@@ -638,26 +614,25 @@ bool Building::LoadGeometry(const std::string &geometryfile)
      return true;
 }
 
-
 void Building::WriteToErrorLog() const
 {
      Log->Write("GEOMETRY: ");
-     for (int i = 0; i < GetNumberOfRooms(); i++) {
+     for (int i = 0; i<GetNumberOfRooms(); i++) {
           Room* r = GetRoom(i);
           r->WriteToErrorLog();
      }
      Log->Write("ROUTING: ");
 
      for (map<int, Crossing*>::const_iterator iter = _crossings.begin();
-               iter != _crossings.end(); ++iter) {
+          iter!=_crossings.end(); ++iter) {
           iter->second->WriteToErrorLog();
      }
      for (map<int, Transition*>::const_iterator iter = _transitions.begin();
-               iter != _transitions.end(); ++iter) {
+          iter!=_transitions.end(); ++iter) {
           iter->second->WriteToErrorLog();
      }
      for (map<int, Hline*>::const_iterator iter = _hLines.begin();
-               iter != _hLines.end(); ++iter) {
+          iter!=_hLines.end(); ++iter) {
           iter->second->WriteToErrorLog();
      }
      Log->Write("\n");
@@ -665,23 +640,22 @@ void Building::WriteToErrorLog() const
 
 Room* Building::GetRoom(string caption) const
 {
-     for(const auto& it: _rooms)
-     {
-          if(it.second->GetCaption()==caption)
+     for (const auto& it: _rooms) {
+          if (it.second->GetCaption()==caption)
                return it.second.get();
      }
-     Log->Write("ERROR: Room not found with caption " + caption);
+     Log->Write("ERROR: Room not found with caption "+caption);
      //return NULL;
      exit(EXIT_FAILURE);
 }
 
 void Building::AddCrossing(Crossing* line)
 {
-     if (_crossings.count(line->GetID()) != 0) {
+     if (_crossings.count(line->GetID())!=0) {
           char tmp[CLENGTH];
           sprintf(tmp,
-                    "ERROR: Duplicate index for crossing found [%d] in Routing::AddCrossing()",
-                    line->GetID());
+                  "ERROR: Duplicate index for crossing found [%d] in Routing::AddCrossing()",
+                  line->GetID());
           Log->Write(tmp);
           exit(EXIT_FAILURE);
      }
@@ -690,11 +664,11 @@ void Building::AddCrossing(Crossing* line)
 
 void Building::AddTransition(Transition* line)
 {
-     if (_transitions.count(line->GetID()) != 0) {
+     if (_transitions.count(line->GetID())!=0) {
           char tmp[CLENGTH];
           sprintf(tmp,
-                    "ERROR: Duplicate index for transition found [%d] in Routing::AddTransition()",
-                    line->GetID());
+                  "ERROR: Duplicate index for transition found [%d] in Routing::AddTransition()",
+                  line->GetID());
           Log->Write(tmp);
           exit(EXIT_FAILURE);
      }
@@ -703,16 +677,17 @@ void Building::AddTransition(Transition* line)
 
 void Building::AddHline(Hline* line)
 {
-     if (_hLines.count(line->GetID()) != 0) {
+     if (_hLines.count(line->GetID())!=0) {
           // check if the lines are identical
-          Hline* ori= _hLines[line->GetID()];
-          if(ori->operator ==(*line)) {
-               Log->Write("INFO: \tSkipping identical hlines with ID [%d]",line->GetID());
+          Hline* ori = _hLines[line->GetID()];
+          if (ori->operator==(*line)) {
+               Log->Write("INFO: \tSkipping identical hlines with ID [%d]", line->GetID());
                return;
-          } else {
+          }
+          else {
                Log->Write(
-                         "ERROR: Duplicate index for hlines found [%d] in Routing::AddHline(). You have [%d] hlines",
-                         line->GetID(), _hLines.size());
+                       "ERROR: Duplicate index for hlines found [%d] in Routing::AddHline(). You have [%d] hlines",
+                       line->GetID(), _hLines.size());
                exit(EXIT_FAILURE);
           }
      }
@@ -721,10 +696,10 @@ void Building::AddHline(Hline* line)
 
 void Building::AddGoal(Goal* goal)
 {
-     if (_goals.count(goal->GetId()) != 0) {
+     if (_goals.count(goal->GetId())!=0) {
           Log->Write(
-                    "ERROR: Duplicate index for goal found [%d] in Routing::AddGoal()",
-                    goal->GetId());
+                  "ERROR: Duplicate index for goal found [%d] in Routing::AddGoal()",
+                  goal->GetId());
           exit(EXIT_FAILURE);
      }
      _goals[goal->GetId()] = goal;
@@ -754,26 +729,27 @@ Transition* Building::GetTransition(string caption) const
 {
      //eventually
      map<int, Transition*>::const_iterator itr;
-     for(itr = _transitions.begin(); itr != _transitions.end(); ++itr) {
-          if (itr->second->GetCaption() == caption)
+     for (itr = _transitions.begin(); itr!=_transitions.end(); ++itr) {
+          if (itr->second->GetCaption()==caption)
                return itr->second;
      }
 
-     Log->Write("WARNING: No Transition with Caption: " + caption);
+     Log->Write("WARNING: No Transition with Caption: "+caption);
      exit(EXIT_FAILURE);
 }
 
 Transition* Building::GetTransition(int ID)
 {
-     if (_transitions.count(ID) == 1) {
+     if (_transitions.count(ID)==1) {
           return _transitions[ID];
-     } else {
-          if (ID == -1)
+     }
+     else {
+          if (ID==-1)
                return NULL;
           else {
                Log->Write(
-                         "ERROR: I could not find any transition with the 'ID' [%d]. You have defined [%d] transitions",
-                         ID, _transitions.size());
+                       "ERROR: I could not find any transition with the 'ID' [%d]. You have defined [%d] transitions",
+                       ID, _transitions.size());
                exit(EXIT_FAILURE);
           }
      }
@@ -781,15 +757,16 @@ Transition* Building::GetTransition(int ID)
 
 Goal* Building::GetFinalGoal(int ID)
 {
-     if (_goals.count(ID) == 1) {
+     if (_goals.count(ID)==1) {
           return _goals[ID];
-     } else {
-          if (ID == -1)
+     }
+     else {
+          if (ID==-1)
                return NULL;
           else {
                Log->Write(
-                         "ERROR: I could not find any goal with the 'ID' [%d]. You have defined [%d] goals",
-                         ID, _goals.size());
+                       "ERROR: I could not find any goal with the 'ID' [%d]. You have defined [%d] goals",
+                       ID, _goals.size());
                exit(EXIT_FAILURE);
           }
      }
@@ -800,65 +777,56 @@ Crossing* Building::GetTransOrCrossByName(string caption) const
      {
           //eventually
           map<int, Transition*>::const_iterator itr;
-          for(itr = _transitions.begin(); itr != _transitions.end(); ++itr)
-          {
-               if (itr->second->GetCaption() == caption)
+          for (itr = _transitions.begin(); itr!=_transitions.end(); ++itr) {
+               if (itr->second->GetCaption()==caption)
                     return itr->second;
           }
      }
      {
           //finally the  crossings
           map<int, Crossing*>::const_iterator itr;
-          for(itr = _crossings.begin(); itr != _crossings.end(); ++itr)
-          {
-               if (itr->second->GetCaption() == caption)
+          for (itr = _crossings.begin(); itr!=_crossings.end(); ++itr) {
+               if (itr->second->GetCaption()==caption)
                     return itr->second;
           }
      }
 
-     Log->Write("WARNING: No Transition or Crossing with Caption: " + caption);
+     Log->Write("WARNING: No Transition or Crossing with Caption: "+caption);
      return NULL;
 }
 
 Hline* Building::GetTransOrCrossByUID(int id) const
 {
-     {
-          //eventually transitions
-          map<int, Transition*>::const_iterator itr;
-          for(itr = _transitions.begin(); itr != _transitions.end(); ++itr)
-          {
-               if (itr->second->GetUniqueID()== id)
-                    return itr->second;
-          }
+     auto hline = GetTransitionByUID(id);
+     if (hline) {
+          return hline;
      }
      {
           //then the  crossings
           map<int, Crossing*>::const_iterator itr;
-          for(itr = _crossings.begin(); itr != _crossings.end(); ++itr)
-          {
-               if (itr->second->GetUniqueID() == id)
+          for (itr = _crossings.begin(); itr!=_crossings.end(); ++itr) {
+               if (itr->second->GetUniqueID()==id)
                     return itr->second;
           }
      }
      {
           //finally the  hlines
-          for(auto itr = _hLines.begin(); itr != _hLines.end(); ++itr)
-          {
-               if (itr->second->GetUniqueID() == id)
+          for (auto itr = _hLines.begin(); itr!=_hLines.end(); ++itr) {
+               if (itr->second->GetUniqueID()==id)
                     return itr->second;
           }
      }
-     Log->Write("ERROR: No Transition or Crossing or hline with ID %d: " ,id);
+     Log->Write("ERROR: No Transition or Crossing or hline with ID %d: ", id);
      return NULL;
 }
 
-SubRoom* Building::GetSubRoomByUID( int uid)
+SubRoom* Building::GetSubRoomByUID(int uid)
 {
-     for(auto& itr_subroom : _allSubRooms) {
-               if(itr_subroom->GetUID()==uid)
-                    return itr_subroom;
+     for (auto& itr_subroom : _allSubRooms) {
+          if (itr_subroom->GetUID()==uid)
+               return itr_subroom;
      }
-     Log->Write("ERROR:\t No subroom exits with the unique id %d",uid);
+     Log->Write("ERROR:\t No subroom exits with the unique id %d", uid);
      return NULL;
 }
 
@@ -878,17 +846,14 @@ SubRoom* Building::GetSubRoomByUID( int uid)
 bool Building::IsVisible(const Point& p1, const Point& p2, const std::vector<SubRoom*>& subrooms, bool considerHlines)
 {
      //loop over all subrooms if none is provided
-     auto checkVisibility = [&](const std::vector<SubRoom*>& subrooms)
-     {
-         for(auto& sub: subrooms)
-         {
-               if(sub && sub->IsVisible(p1,p2,considerHlines)==false) return false;
-         }
-         return true;
+     auto checkVisibility = [&](const std::vector<SubRoom*>& subrooms) {
+          for (auto& sub: subrooms) {
+               if (sub && sub->IsVisible(p1, p2, considerHlines)==false) return false;
+          }
+          return true;
 
      };
-     if (subrooms.empty())
-     {
+     if (subrooms.empty()) {
           return checkVisibility(_allSubRooms);
      }
      return checkVisibility(subrooms);
@@ -897,9 +862,8 @@ bool Building::IsVisible(const Point& p1, const Point& p2, const std::vector<Sub
 bool Building::Triangulate()
 {
      Log->Write("INFO:\tTriangulating the geometry");
-     for(auto& itr_subroom: _allSubRooms)
-     {
-          if(!itr_subroom->Triangulate())
+     for (auto& itr_subroom: _allSubRooms) {
+          if (!itr_subroom->Triangulate())
                return false;
      }
      Log->Write("INFO:\tDone...");
@@ -911,8 +875,7 @@ bool Building::SanityCheck()
      Log->Write("INFO: \tChecking the geometry for artifacts");
      bool status = true;
 
-     for(auto& itr_subroom : _allSubRooms)
-     {
+     for (auto& itr_subroom : _allSubRooms) {
           if (!itr_subroom->SanityCheck())
                status = false;
      }
@@ -920,10 +883,8 @@ bool Building::SanityCheck()
      return status;
 }
 
-
 #ifdef _SIMULATOR
 
-
 void Building::UpdateGrid()
 {
      _linkedCellGrid->Update(_allPedestians);
@@ -939,8 +900,8 @@ void Building::InitGrid(double cellSize)
 
      //finding the bounding of the grid
      // and collect the pedestrians
-     for(auto&& itr_subroom: _allSubRooms) {
-          for (auto &&wall:itr_subroom->GetAllWalls()) {
+     for (auto&& itr_subroom: _allSubRooms) {
+          for (auto&& wall:itr_subroom->GetAllWalls()) {
                x_min = std::min({wall.GetPoint1()._x, wall.GetPoint2()._x, x_min});
                x_max = std::max({wall.GetPoint1()._x, wall.GetPoint2()._x, x_max});
                y_max = std::max({wall.GetPoint1()._y, wall.GetPoint2()._y, y_max});
@@ -949,24 +910,26 @@ void Building::InitGrid(double cellSize)
      }
 
      //make the grid slightly larger.
-     x_min = x_min - 1*cellSize;
-     x_max = x_max + 1*cellSize;
-     y_min = y_min - 1*cellSize;
-     y_max = y_max + 1*cellSize;
+     x_min = x_min-1*cellSize;
+     x_max = x_max+1*cellSize;
+     y_min = y_min-1*cellSize;
+     y_max = y_max+1*cellSize;
 
-     double boundaries[4] = { x_min, x_max, y_min, y_max };
+     double boundaries[4] = {x_min, x_max, y_min, y_max};
 
      //no algorithms
      // the domain is made of a single cell
-     if(cellSize==-1) {
+     if (cellSize==-1) {
           Log->Write("INFO: \tBrute Force will be used for neighborhoods query");
-          if ( (x_max-x_min) < (y_max-y_min) ) {
-               cellSize=(y_max-y_min);
-          } else {
-               cellSize=(x_max-x_min);
+          if ((x_max-x_min)<(y_max-y_min)) {
+               cellSize = (y_max-y_min);
+          }
+          else {
+               cellSize = (x_max-x_min);
           }
 
-     } else {
+     }
+     else {
           Log->Write("INFO: \tInitializing the grid with cell size: %f ", cellSize);
      }
 
@@ -976,10 +939,10 @@ void Building::InitGrid(double cellSize)
      Log->Write("INFO: \tDone with Initializing the grid ");
 }
 
-bool Building::LoadRoutingInfo(const string &filename)
+bool Building::LoadRoutingInfo(const string& filename)
 {
      Log->Write("INFO:\tLoading extra routing information");
-     if (filename == "") {
+     if (filename=="") {
           Log->Write("INFO:\t No file supplied !");
           Log->Write("INFO:\t done with loading extra routing information");
           return true;
@@ -992,26 +955,24 @@ bool Building::LoadRoutingInfo(const string &filename)
      }
 
      TiXmlElement* xRootNode = docRouting.RootElement();
-     if( ! xRootNode ) {
+     if (!xRootNode) {
           Log->Write("ERROR:\tRoot element does not exist");
           return false;
      }
 
-     if (! xRootNode->FirstChild("routing"))
-     {
+     if (!xRootNode->FirstChild("routing")) {
           return true; // no extra routing information
      }
      //load goals and routes
-     TiXmlNode*  xGoalsNode = xRootNode->FirstChild("routing")->FirstChild("goals");
-
+     TiXmlNode* xGoalsNode = xRootNode->FirstChild("routing")->FirstChild("goals");
 
-     if(xGoalsNode)
-          for(TiXmlElement* e = xGoalsNode->FirstChildElement("goal"); e;
-                    e = e->NextSiblingElement("goal")) {
+     if (xGoalsNode)
+          for (TiXmlElement* e = xGoalsNode->FirstChildElement("goal"); e;
+               e = e->NextSiblingElement("goal")) {
 
                int id = xmltoi(e->Attribute("id"), -1);
-               int isFinal= string(e->Attribute("final"))=="true";
-               string caption = xmltoa(e->Attribute("caption"),"-1");
+               int isFinal = string(e->Attribute("final"))=="true";
+               string caption = xmltoa(e->Attribute("caption"), "-1");
 
                Goal* goal = new Goal();
                goal->SetId(id);
@@ -1019,13 +980,13 @@ bool Building::LoadRoutingInfo(const string &filename)
                goal->SetIsFinalGoal(isFinal);
 
                //looking for polygons (walls)
-               for(TiXmlElement* xPolyVertices = e->FirstChildElement("polygon"); xPolyVertices;
-                         xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {
+               for (TiXmlElement* xPolyVertices = e->FirstChildElement("polygon"); xPolyVertices;
+                    xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {
 
                     for (TiXmlElement* xVertex = xPolyVertices->FirstChildElement(
-                              "vertex");
-                              xVertex && xVertex != xPolyVertices->LastChild("vertex");
-                              xVertex = xVertex->NextSiblingElement("vertex")) {
+                            "vertex");
+                         xVertex && xVertex!=xPolyVertices->LastChild("vertex");
+                         xVertex = xVertex->NextSiblingElement("vertex")) {
 
                          double x1 = xmltof(xVertex->Attribute("px"));
                          double y1 = xmltof(xVertex->Attribute("py"));
@@ -1035,7 +996,7 @@ bool Building::LoadRoutingInfo(const string &filename)
                     }
                }
 
-               if(!goal->ConvertLineToPoly())
+               if (!goal->ConvertLineToPoly())
                     return false;
 
                AddGoal(goal);
@@ -1043,14 +1004,14 @@ bool Building::LoadRoutingInfo(const string &filename)
           }
 
      //load routes
-     TiXmlNode*  xTripsNode = xRootNode->FirstChild("routing")->FirstChild("routes");
+     TiXmlNode* xTripsNode = xRootNode->FirstChild("routing")->FirstChild("routes");
 
-     if(xTripsNode)
-          for(TiXmlElement* trip = xTripsNode->FirstChildElement("route"); trip;
-                    trip = trip->NextSiblingElement("route")) {
+     if (xTripsNode)
+          for (TiXmlElement* trip = xTripsNode->FirstChildElement("route"); trip;
+               trip = trip->NextSiblingElement("route")) {
 
                double id = xmltof(trip->Attribute("id"), -1);
-               if (id == -1) {
+               if (id==-1) {
                     Log->Write("ERROR:\t id missing for trip");
                     return false;
                }
@@ -1059,7 +1020,7 @@ bool Building::LoadRoutingInfo(const string &filename)
                vTrip.clear();
 
                char* str = (char*) sTrip.c_str();
-               char *p = strtok(str, ":");
+               char* p = strtok(str, ":");
                while (p) {
                     vTrip.push_back(xmltoa(p));
                     p = strtok(NULL, ":");
@@ -1075,7 +1036,7 @@ bool Building::LoadTrafficInfo()
 
      Log->Write("INFO:\tLoading  the traffic info file");
 
-     string trafficFile="";
+     string trafficFile = "";
      TiXmlDocument doc(_projectFilename);
      if (!doc.LoadFile()) {
           Log->Write("ERROR: \t%s", doc.ErrorDesc());
@@ -1084,38 +1045,40 @@ bool Building::LoadTrafficInfo()
      }
 
      TiXmlNode* xRootNode = doc.RootElement()->FirstChild("traffic_constraints");
-     if( ! xRootNode ) {
+     if (!xRootNode) {
           Log->Write("WARNING:\tcould not find any traffic information");
           return true;
      }
 
      //processing the rooms node
-     TiXmlNode*  xRoomsNode = xRootNode->FirstChild("rooms");
-     if(xRoomsNode)
-          for(TiXmlElement* xRoom = xRoomsNode->FirstChildElement("room"); xRoom;
-                    xRoom = xRoom->NextSiblingElement("room")) {
+     TiXmlNode* xRoomsNode = xRootNode->FirstChild("rooms");
+     if (xRoomsNode)
+          for (TiXmlElement* xRoom = xRoomsNode->FirstChildElement("room"); xRoom;
+               xRoom = xRoom->NextSiblingElement("room")) {
 
                double id = xmltof(xRoom->Attribute("room_id"), -1);
                string state = xmltoa(xRoom->Attribute("state"), "good");
-               RoomState status = (state == "good") ? ROOM_CLEAN : ROOM_SMOKED;
+               RoomState status = (state=="good") ? ROOM_CLEAN : ROOM_SMOKED;
                GetRoom(id)->SetState(status);
           }
 
      //processing the doors node
-     TiXmlNode*  xDoorsNode = xRootNode->FirstChild("doors");
-     if(xDoorsNode)
-          for(TiXmlElement* xDoor = xDoorsNode->FirstChildElement("door"); xDoor;
-                    xDoor = xDoor->NextSiblingElement("door")) {
+     TiXmlNode* xDoorsNode = xRootNode->FirstChild("doors");
+     if (xDoorsNode)
+          for (TiXmlElement* xDoor = xDoorsNode->FirstChildElement("door"); xDoor;
+               xDoor = xDoor->NextSiblingElement("door")) {
 
                int id = xmltoi(xDoor->Attribute("trans_id"), -1);
                string state = xmltoa(xDoor->Attribute("state"), "open");
 
                //store transition in a map and call getTransition/getCrossin
-               if (state == "open") {
+               if (state=="open") {
                     GetTransition(id)->Open();
-               } else if (state == "close") {
+               }
+               else if (state=="close") {
                     GetTransition(id)->Close();
-               } else {
+               }
+               else {
                     Log->Write("WARNING:\t Unknown door state: %s", state.c_str());
                }
           }
@@ -1123,45 +1086,44 @@ bool Building::LoadTrafficInfo()
      return true;
 }
 
-
-void Building::DeletePedestrian(Pedestrian* &ped)
+void Building::DeletePedestrian(Pedestrian*& ped)
 {
      vector<Pedestrian*>::iterator it;
      it = find(_allPedestians.begin(), _allPedestians.end(), ped);
-     if (it == _allPedestians.end()) {
-          Log->Write ("\tERROR: \tPed not found with ID %d ",ped->GetID());
+     if (it==_allPedestians.end()) {
+          Log->Write("\tERROR: \tPed not found with ID %d ", ped->GetID());
           exit(EXIT_FAILURE);
           return;
-     } else {
+     }
+     else {
           // save the path history for this pedestrian before removing from the simulation
           if (_savePathway) {
                string results;
                string path = (*it)->GetPath();
                vector<string> brokenpaths;
                StringExplode(path, ">", &brokenpaths);
-               for (unsigned int i = 0; i < brokenpaths.size(); i++) {
+               for (unsigned int i = 0; i<brokenpaths.size(); i++) {
                     vector<string> tags;
                     StringExplode(brokenpaths[i], ":", &tags);
                     string room = _rooms[atoi(tags[0].c_str())]->GetCaption();
-                    string trans =GetTransition(atoi(tags[1].c_str()))->GetCaption();
+                    string trans = GetTransition(atoi(tags[1].c_str()))->GetCaption();
                     //ignore crossings/hlines
-                    if (trans != "")
+                    if (trans!="")
                          _pathWayStream << room << " " << trans << endl;
                }
 
           }
           //cout << "rescued agent: " << (*it)->GetID()<<endl;
 
-          static int totalPeds= _allPedestians.size();
+          static int totalPeds = _allPedestians.size();
           _allPedestians.erase(it);
 
-          int nowPeds= _allPedestians.size();
+          int nowPeds = _allPedestians.size();
           Log->ProgressBar(totalPeds, totalPeds-nowPeds);
      }
      //update the stats before deleting
-     Transition* trans =GetTransitionByUID(ped->GetExitIndex());
-     if(trans)
-     {
+     Transition* trans = GetTransitionByUID(ped->GetExitIndex());
+     if (trans) {
           trans->IncreaseDoorUsage(1, ped->GetGlobalTime());
      }
      delete ped;
@@ -1175,186 +1137,170 @@ const vector<Pedestrian*>& Building::GetAllPedestrians() const
 
 void Building::AddPedestrian(Pedestrian* ped)
 {
-     for(unsigned int p = 0;p<_allPedestians.size();p++){
-          Pedestrian* ped1=_allPedestians[p];
-          if(ped->GetID()==ped1->GetID()){
-               cout<<"Pedestrian already in the room ??? "<<ped->GetID()<<endl;
-               return;
-          }
-     }
+     if (std::count_if(_allPedestians.begin(), _allPedestians.end(),
+             [&](Pedestrian* const pedestrian) { return pedestrian->GetID()==ped->GetID(); })==0) {
      _allPedestians.push_back(ped);
+     }
+     else {
+          cout << "Pedestrian already in the room ??? " << ped->GetID() << endl;
+     }
 }
 
 void Building::GetPedestrians(int room, int subroom, std::vector<Pedestrian*>& peds) const
 {
-     for (auto& ped : _allPedestians)
-     {
-          if ((room == ped->GetRoomID()) && (subroom == ped->GetSubRoomID()))
-          {
+     for (auto& ped : _allPedestians) {
+          if ((room==ped->GetRoomID()) && (subroom==ped->GetSubRoomID())) {
                peds.push_back(ped);
           }
      }
 }
 
 void Building::StringExplode(string str, string separator,
-          vector<string>* results)
+        vector<string>* results)
 {
      size_t found;
      found = str.find_first_of(separator);
-     while (found != string::npos) {
-          if (found > 0) {
+     while (found!=string::npos) {
+          if (found>0) {
                results->push_back(str.substr(0, found));
           }
-          str = str.substr(found + 1);
+          str = str.substr(found+1);
           found = str.find_first_of(separator);
      }
-     if (str.length() > 0) {
+     if (str.length()>0) {
           results->push_back(str);
      }
 }
 
-Pedestrian* Building::GetPedestrian(int pedID) const
+Pedestrian* Building::GetPedestrian(size_t pedID) const
 {
-     auto pediterator = std::find_if(_allPedestians.begin(), _allPedestians.end(), [&](Pedestrian *const pedestrian){return (pedestrian->GetID() == pedID);});
-     if (pediterator == _allPedestians.end()) {
-          return nullptr;
-     }
-     return *pediterator;
+     return _allPedestians.at(pedID);
 }
 
 Transition* Building::GetTransitionByUID(int uid) const
 {
-     //eventually
 
-     for(auto& itr : _transitions) {
-          if (itr.second->GetUniqueID()== uid)
-               return itr.second;
+     //eventually
+     auto it = std::find_if(_transitions.cbegin(), _transitions.cend(),
+             [&](const std::pair<int, Transition*>& item) { return item.second->GetUniqueID()==uid; });
+     if (it==_transitions.end()) {
+          return nullptr;
      }
-     return nullptr;
+     std::cout << it->first << " " << it->second->GetUniqueID() << std::endl;
+     return it->second;
 }
 
-
-bool Building::SaveGeometry(const std::string &filename)
+bool Building::SaveGeometry(const std::string& filename)
 {
      std::stringstream geometry;
 
      //write the header
-     geometry<< "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"<<endl;
-     geometry<< "<geometry version=\"0.5\" caption=\"second life\" unit=\"m\"\n "
-               " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n  "
-               " xsi:noNamespaceSchemaLocation=\"http://134.94.2.137/jps_geoemtry.xsd\">"<<endl<<endl;
+     geometry << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" << endl;
+     geometry << "<geometry version=\"0.5\" caption=\"second life\" unit=\"m\"\n "
+             " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n  "
+             " xsi:noNamespaceSchemaLocation=\"http://134.94.2.137/jps_geoemtry.xsd\">" << endl << endl;
 
      //write the rooms
-     geometry<<"<rooms>"<<endl;
-     for (auto&& itroom : _rooms)
-     {
-          auto&& room=itroom.second;
-          geometry<<"\t<room id =\""<<room->GetID()<<"\" caption =\""<<room->GetCaption()<<"\">"<<endl;
-          for(auto&& itr_sub : room->GetAllSubRooms())
-          {
-               auto&& sub=itr_sub.second;
-               const double* plane=sub->GetPlaneEquation();
-               geometry<<"\t\t<subroom id =\""<<sub->GetSubRoomID()
-                                  <<"\" closed=\""<<0
-                                  <<"\" class=\""<<sub->GetType()
-                                  <<"\" A_x=\""<<plane[0]
-                                                       <<"\" B_y=\""<<plane[1]
-                                                                            <<"\" C_z=\""<<plane[2]<<"\">"<<endl;
-
-
-               for (auto&& wall : sub->GetAllWalls())
-               {
-                    const Point& p1=wall.GetPoint1();
-                    const Point& p2=wall.GetPoint2();
-
-                    geometry<<"\t\t\t<polygon caption=\"wall\" type=\""<<wall.GetType()<<"\">"<<endl
-                              <<"\t\t\t\t<vertex px=\""<<p1._x<<"\" py=\""<<p1._y<<"\"/>"<<endl
-                              <<"\t\t\t\t<vertex px=\""<<p2._x<<"\" py=\""<<p2._y<<"\"/>"<<endl
-                              <<"\t\t\t</polygon>"<<endl;
+     geometry << "<rooms>" << endl;
+     for (auto&& itroom : _rooms) {
+          auto&& room = itroom.second;
+          geometry << "\t<room id =\"" << room->GetID() << "\" caption =\"" << room->GetCaption() << "\">" << endl;
+          for (auto&& itr_sub : room->GetAllSubRooms()) {
+               auto&& sub = itr_sub.second;
+               const double* plane = sub->GetPlaneEquation();
+               geometry << "\t\t<subroom id =\"" << sub->GetSubRoomID()
+                       << "\" closed=\"" << 0
+                       << "\" class=\"" << sub->GetType()
+                       << "\" A_x=\"" << plane[0]
+                       << "\" B_y=\"" << plane[1]
+                       << "\" C_z=\"" << plane[2] << "\">" << endl;
+
+               for (auto&& wall : sub->GetAllWalls()) {
+                    const Point& p1 = wall.GetPoint1();
+                    const Point& p2 = wall.GetPoint2();
+
+                    geometry << "\t\t\t<polygon caption=\"wall\" type=\"" << wall.GetType() << "\">" << endl
+                            << "\t\t\t\t<vertex px=\"" << p1._x << "\" py=\"" << p1._y << "\"/>" << endl
+                            << "\t\t\t\t<vertex px=\"" << p2._x << "\" py=\"" << p2._y << "\"/>" << endl
+                            << "\t\t\t</polygon>" << endl;
                }
 
-               if(sub->GetType()=="stair")
-               {
-                    const Point& up = ((Stair*)sub.get())->GetUp();
-                    const Point& down = ((Stair*)sub.get())->GetDown();
-                    geometry<<"\t\t\t<up px=\""<<up._x<<"\" py=\""<<up._y<<"\"/>"<<endl;
-                    geometry<<"\t\t\t<down px=\""<<down._x<<"\" py=\""<<down._y<<"\"/>"<<endl;
+               if (sub->GetType()=="stair") {
+                    const Point& up = ((Stair*) sub.get())->GetUp();
+                    const Point& down = ((Stair*) sub.get())->GetDown();
+                    geometry << "\t\t\t<up px=\"" << up._x << "\" py=\"" << up._y << "\"/>" << endl;
+                    geometry << "\t\t\t<down px=\"" << down._x << "\" py=\"" << down._y << "\"/>" << endl;
                }
 
-               geometry<<"\t\t</subroom>"<<endl;
+               geometry << "\t\t</subroom>" << endl;
           }
 
           //write the crossings
-          geometry<<"\t\t<crossings>"<<endl;
-          for (auto const& mapcross : _crossings)
-          {
-               Crossing* cross=mapcross.second;
+          geometry << "\t\t<crossings>" << endl;
+          for (auto const& mapcross : _crossings) {
+               Crossing* cross = mapcross.second;
 
                //only write the crossings in this rooms
-               if(cross->GetRoom1()->GetID()!=room->GetID()) continue;
+               if (cross->GetRoom1()->GetID()!=room->GetID()) continue;
 
-               const Point& p1=cross->GetPoint1();
-               const Point& p2=cross->GetPoint2();
+               const Point& p1 = cross->GetPoint1();
+               const Point& p2 = cross->GetPoint2();
 
-               geometry<<"\t<crossing id =\""<<cross->GetID()
-                                  <<"\" subroom1_id=\""<<cross->GetSubRoom1()->GetSubRoomID()
-                                  <<"\" subroom2_id=\""<<cross->GetSubRoom2()->GetSubRoomID()<<"\">"<<endl;
+               geometry << "\t<crossing id =\"" << cross->GetID()
+                       << "\" subroom1_id=\"" << cross->GetSubRoom1()->GetSubRoomID()
+                       << "\" subroom2_id=\"" << cross->GetSubRoom2()->GetSubRoomID() << "\">" << endl;
 
-               geometry<<"\t\t<vertex px=\""<<p1._x<<"\" py=\""<<p1._y<<"\"/>"<<endl
-                         <<"\t\t<vertex px=\""<<p2._x<<"\" py=\""<<p2._y<<"\"/>"<<endl
-                         <<"\t</crossing>"<<endl;
+               geometry << "\t\t<vertex px=\"" << p1._x << "\" py=\"" << p1._y << "\"/>" << endl
+                       << "\t\t<vertex px=\"" << p2._x << "\" py=\"" << p2._y << "\"/>" << endl
+                       << "\t</crossing>" << endl;
           }
-          geometry<<"\t\t</crossings>"<<endl;
-          geometry<<"\t</room>"<<endl;
+          geometry << "\t\t</crossings>" << endl;
+          geometry << "\t</room>" << endl;
      }
 
-     geometry<<"</rooms>"<<endl;
+     geometry << "</rooms>" << endl;
 
      //write the transitions
-     geometry<<"<transitions>"<<endl;
-
-     for (auto const& maptrans : _transitions)
-     {
-          Transition* trans=maptrans.second;
-          const Point& p1=trans->GetPoint1();
-          const Point& p2=trans->GetPoint2();
-          int room2_id=-1;
-          int subroom2_id=-1;
-          if(trans->GetRoom2())
-          {
-               room2_id=trans->GetRoom2()->GetID();
-               subroom2_id=trans->GetSubRoom2()->GetSubRoomID();
+     geometry << "<transitions>" << endl;
+
+     for (auto const& maptrans : _transitions) {
+          Transition* trans = maptrans.second;
+          const Point& p1 = trans->GetPoint1();
+          const Point& p2 = trans->GetPoint2();
+          int room2_id = -1;
+          int subroom2_id = -1;
+          if (trans->GetRoom2()) {
+               room2_id = trans->GetRoom2()->GetID();
+               subroom2_id = trans->GetSubRoom2()->GetSubRoomID();
           }
 
-          geometry<<"\t<transition id =\""<<trans->GetID()
-                             <<"\" caption=\""<<trans->GetCaption()
-                             <<"\" type=\""<<trans->GetType()
-                             <<"\" room1_id=\""<<trans->GetRoom1()->GetID()
-                             <<"\" subroom1_id=\""<<trans->GetSubRoom1()->GetSubRoomID()
-                             <<"\" room2_id=\""<<room2_id
-                             <<"\" subroom2_id=\""<<subroom2_id<<"\">"<<endl;
+          geometry << "\t<transition id =\"" << trans->GetID()
+                  << "\" caption=\"" << trans->GetCaption()
+                  << "\" type=\"" << trans->GetType()
+                  << "\" room1_id=\"" << trans->GetRoom1()->GetID()
+                  << "\" subroom1_id=\"" << trans->GetSubRoom1()->GetSubRoomID()
+                  << "\" room2_id=\"" << room2_id
+                  << "\" subroom2_id=\"" << subroom2_id << "\">" << endl;
 
-          geometry<<"\t\t<vertex px=\""<<p1._x<<"\" py=\""<<p1._y<<"\"/>"<<endl
-                    <<"\t\t<vertex px=\""<<p2._x<<"\" py=\""<<p2._y<<"\"/>"<<endl
-                    <<"\t</transition>"<<endl;
+          geometry << "\t\t<vertex px=\"" << p1._x << "\" py=\"" << p1._y << "\"/>" << endl
+                  << "\t\t<vertex px=\"" << p2._x << "\" py=\"" << p2._y << "\"/>" << endl
+                  << "\t</transition>" << endl;
 
      }
 
-     geometry<<"</transitions>"<<endl;
-     geometry<<"</geometry>"<<endl;
+     geometry << "</transitions>" << endl;
+     geometry << "</geometry>" << endl;
      //write the routing file
 
      //cout<<endl<<geometry.str()<<endl;
 
-     ofstream geofile (filename);
-     if(geofile.is_open())
-     {
-          geofile<<geometry.str();
-          Log->Write("INFO:\tfile saved to %s",filename.c_str());
+     ofstream geofile(filename);
+     if (geofile.is_open()) {
+          geofile << geometry.str();
+          Log->Write("INFO:\tfile saved to %s", filename.c_str());
      }
-     else
-     {
-          Log->Write("ERROR:\tunable to save the geometry to %s",filename.c_str());
+     else {
+          Log->Write("ERROR:\tunable to save the geometry to %s", filename.c_str());
           return false;
      }
 
diff --git a/geometry/Building.h b/geometry/Building.h
index e4e16f2e42e86138af05ce3d8fee2f0e8c48214b..4db9c0fe5803c0067659bab6d0caa41c0adf8434 100644
--- a/geometry/Building.h
+++ b/geometry/Building.h
@@ -92,7 +92,7 @@ public:
      RoutingEngine* GetRoutingEngine() const;
      const std::map<int, std::unique_ptr<Room> >& GetAllRooms() const;
      const std::vector<Pedestrian*>& GetAllPedestrians() const;
-     Pedestrian* GetPedestrian( int pedID) const;
+     Pedestrian* GetPedestrian( size_t pedID) const;
      int GetNumberOfRooms() const;
      int GetNumberOfGoals()const;
      Room* GetRoom(int index) const;
diff --git a/geometry/Line.cpp b/geometry/Line.cpp
index 8dc1cc12623dcc7e024fa9eb1b114a2e80015133..408dd661948c86fec2a3a47cbeb649db8d7fbd21 100644
--- a/geometry/Line.cpp
+++ b/geometry/Line.cpp
@@ -37,7 +37,7 @@
 #include  <cmath>
 #include  <sstream>
 
-int Line::_static_UID = 0;
+unsigned int Line::_static_UID = 0;
 
 using namespace std;
 
@@ -55,7 +55,7 @@ Line::Line(const Point &p1, const Point &p2) : _point1(p1), _point2(p2), _centre
     _uid = _static_UID++;
 }
 
-int Line::GetUniqueID() const {
+unsigned int Line::GetUniqueID() const {
     return _uid;
 }
 
diff --git a/geometry/Line.h b/geometry/Line.h
index c2d537e08bb7d50af2796862dea0deb021a9b328..47870d093c4e6ace5869d4e8c29b9ef710273865 100644
--- a/geometry/Line.h
+++ b/geometry/Line.h
@@ -51,8 +51,8 @@ private:
      Point _centre;
 
      //unique identifier for all line elements
-     static int _static_UID;
-     int _uid;
+     static unsigned int _static_UID;
+     unsigned int _uid;
 
 public:
 
@@ -65,7 +65,7 @@ public:
       * All Line elements (also derived class) have a unique ID
       * @return the unique ID of this line element.
       */
-     int GetUniqueID() const;
+     unsigned int GetUniqueID() const;
 
      /**
       * Set/Get the first end point of the line