tested toplevel refactor