Refactoring/tiny perf changes