Cleanup and try to avoid calling resolve() twice