Refactored (made smaller functions.)