Adding promise check for defer