Refactor some profile code