Fixed cleanup of resources when tests finish.