Refactor the home page controller code