refactor to prepare performance improvements