refactoring: make it top level