midway through re-implementing functions using module pattern; more time consuming than I expected