Fixed bug that the resolve functions were called twice.