Continue refactor of top-level functions