Refactored a bit of Site_controller.php