Fixed clean up function