Code learned by me from pluralsight course.