factor out helper functions and globals into modules