added insert_leave call in prepare_system_for_leave