refactoring top level