Additional refactoring and cleanup related to profiling