Fix profile editing; #597

The code ain't pretty, but it works. I think.