Some refactoring for profiling