most of the interesting code duplicated from course materials