Move profile handling into a separate file in core/.