more attempts at perf enhancements / refactoring