move profile handler into own func plus cleanup