refactor for improved scaling