Various fixes allowing cleanup to happen correctly