Refactor to put profiling stuff in a separate module.