Major changes in mainBuilding.php logic, corrected some bugs