Refactor the site controller to use global functions