Finished function programming, clarified each piece with comments.