Fix bugs with profile switching.