image: Some fixes on the cleanup functions