added the cleaning up mechanism