FINISHED CODE WITH CHANGES FROM LECTURE