fixed cleanup to execute on close