Improved method to delete profile

Fixed #13586
Fixed #13581