refactoring (untested)