Cleanupfunction

@kalbermattenm : please review. thanks