generalized and fixed contact removal function paradedev/cms#1588