Better cleanup of resources, although a few textures are still leaked after exit.