Refactored code to not be split over the view as well.