Restructured deletion of functions, some minor fixes