Worked on final solution with functions