completed recode of Friday's work, much cleaner, much more functional